anon
anon

Reputation:

How to improve the quality of JPEG images that are generated from PDFs using Ghostscript?

I use this code to generate JPEG images from a PDF file:

String cmd = @"./lib/gswin32c";
String args = "-dNOPAUSE -sDEVICE=jpeg -dJPEGQ=100 -dBATCH -dSAFER -sOutputFile=" + fileName + "-%03d.jpg " + fileName + ".pdf";
Process proc = new Process();
proc.StartInfo.FileName = cmd;
proc.StartInfo.Arguments = args;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;
proc.Start();

I works really fine, but the quality is really bad. It seems to be blurred. Any hints how to improve the quality?

EDIT

Now I'm using the following arguments and it is working as expected:

String args = "-dNOPAUSE -sDEVICE=pngalpha -r300 -dBATCH -dSAFER -sOutputFile=" + fileName + "-%03d" + FILEEXTENSION + " " + fileName + ".pdf";

Upvotes: 4

Views: 5482

Answers (3)

Shawn Vader
Shawn Vader

Reputation: 12385

I have just been struggling with the quality of a pdf to jpeg and have changed on the advice of dk-logic to gif.

This may help someone because I now have near perfect quality with the following command

gs -sDEVICE=png16m -r600 -dDownScaleFactor=3 -o outfile.png inFile.pdf

According the the docs

-dDownScaleFactor=integer

This causes the internal rendering to be scaled down by the given (small integer) factor before being output. For example, the above will produce a 200dpi output png from a 600dpi internal rendering:

Upvotes: 1

SK-logic
SK-logic

Reputation: 9714

JPEG? For documents? Generate gifs or pngs, if you can. JPEGs are unsuitable for anything else than photos, even at a "maximum" quality setting.

http://lbrandy.com/blog/2008/10/my-first-and-last-webcomic/

Upvotes: 2

young
young

Reputation: 2181

I've quickly look through the document and it seems there are some options to affect image quality like -dCOLORSCREEN and -dDOINTERPOLATE. Try them! :)

Upvotes: 1

Related Questions