Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GhostscriptRasterizer.GetPage Setting DPI has no impact on the resulting raster #108

Open
MarcChasse opened this issue Feb 15, 2023 · 0 comments

Comments

@MarcChasse
Copy link

In the following demo program I would expect the HorizontalResolution and VerticalResolution to both be set to the dpi value passed into GhostscriptRasterizer.GetPage but it seems ot have no impact and resulting document always have 96 as the Horizontal and Vertical Resolution.

static void Main(string[] args)
{
    using (FileStream fs = File.OpenRead(@"C:\temp\annots.pdf"))
    {
        var mytiff = ProcessMemoryStream(fs);
        FileStream file = new FileStream(@"C:\temp\ghostscript.tif", FileMode.Create, FileAccess.Write);
        mytiff.WriteTo(file);
        file.Close();
        mytiff.Close();
    }
    Console.ReadKey();
}
static MemoryStream ProcessMemoryStream(FileStream inputMS)
{
    var gv = new GhostscriptVersionInfo(@"C:\Program Files\gs\gs10.00.0\bin\gsdll64.dll");
    using (var rasterizer = new GhostscriptRasterizer())
    {
        rasterizer.Open(inputMS, gv, false);

        MemoryStream tiffStream = new MemoryStream();

        System.Drawing.Image img = rasterizer.GetPage(300, 2);
        Console.WriteLine($"{img.Width}x{img.Height}");
        Console.WriteLine($"{img.HorizontalResolution}x{img.VerticalResolution}"); // <---- Always prints 96x96 regardless of the dpi value above
        img.Save(tiffStream, ImageFormat.Tiff);

        rasterizer.Close();
        return tiffStream;
    }
}

I'm usign the latest version of Ghostscript, 10.0.0.0 and of Ghostscript.NET, 1.2.3.
I've also tried using the latest version of Ghostscript.NET from main and changing the hardcoded default values tform 96 to 300 with no impact:

    public class GhostscriptViewer : IDisposable
    {
        ...
        private int _zoom_xDpi = 300;
        private int _zoom_yDpi = 300;
        ...
    }

Thanks for building a great wrapper
Ultimately I would like to emulate this command in code and i think all i need is the Resolution now

gswin64c -dSAFER -dBATCH -dNOPAUSE -sDEVICE=tiff24nc -dGraphicsAlphaBits=4 -sCompression=lzw -r300 -dMaxStripSize=0 -sOutputFile=tiger.tif Original.pdf

FYI there was a change to fix this issue but that seems to not have worked:
x and y dpi ignores the set value #75

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant