GhostScriptSharp resolution problems

2.8k Views Asked by At

I am trying to create a thumbnail from a PDF file, but I need it to be 300px*300px but no matter what I do I can not get the image to be the correct size. It always seems to be huge.

This is my code:

        GhostscriptSettings settings = new GhostscriptSettings();
        settings.Page.AllPages = false;
        settings.Page.Start = 1;
        settings.Page.End = 1;
        settings.Size.Native = GhostscriptSharp.Settings.GhostscriptPageSizes.a2;
        settings.Device = GhostscriptSharp.Settings.GhostscriptDevices.png16m;
        settings.Resolution = new Size(72, 72);

        GhostscriptWrapper.GenerateOutput(Path.Combine(FilePath, Filename), FinalPath, settings); // Create the initial thumbnail

Is there any way to output an image with the PPI of 300*300 ?

Cheers,

/r3plica

1

There are 1 best solutions below

1
On

Looks to me like you are setting a resolution of 300x300. That is 300 dots per inch, which will give you reasonably large files.

You want to change the page size, which looks to me like you are setting to A2. An A2 page at 300 dpi will indeed produce very large output files.....

I have no idea how you would change the media size in C#. The Ghostscript command line switches you need are -dDEVICEWIDTH=300 -dDEVICEHEIGHT=300 -dFIXEDMEDIA

You say you are using a 'PSD' file, which would suggest Photoshop native file format to me, which Ghostscript won't interpret. Possibly you mean a PDF file, in which case you should also add -dPDFFitPage. If on the other hand you mean a PS (PostScript) file, you should set the PageSize Policy to 3 (select nearest media and scale down).