How to convert PDF to JPEG with low resolution (but good quality)?

When I use the following ghostscript command to create jpg thumbnails from PDF files, image quality is often very poor:

gs -q -dNOPAUSE -dBATCH -sDEVICE=jpeggray -g465x600 -dUseCropBox -dPDFFitPage -sOutputFile=pdf_to_lowres.jpg test.pdf 

In contrast, if I use ghostscript to generate high resolution png and then use mogrify to convert high-res png to low-res jpg, I get pretty good results.

 gs -q -dNOPAUSE -dBATCH -sDEVICE=pnggray -g2550x3300 -dUseCropBox -dPDFFitPage -sOutputFile=pdf_to_highres.png test.pdf mogrify -thumbnail 465x600 -format jpg -write pdf_to_highres_to_lowres.jpg pdf_to_highres.png 

Is there a way to achieve good results bypassing the intermediate step pdf → high-res png? I need to do this for a large number of PDF files, so I'm trying to minimize the calculation time.

Here are the links to the images mentioned above:

+6
source share
2 answers

One option that seems to greatly improve the output: -dDOINTERPOLATE . Here is what I got by executing the same command as you, but with the -dDOINTERPOLATE option:

JPEG with -dDOINTERPOLATE

I'm not sure if this method uses interpolation , but it seems pretty good, especially compared to the results without it.

PS Consider displaying PNG images ( -sDEVICE=pnggray ) instead of JPEG. For most PDF documents (which usually have only a few solid colors), a more suitable choice.

+5
source

Your PDF looks like it's already a wrapper around jpeg.

Try using the pdfimages program from xpdf to extract the actual image, and not to render to a file.

+3
source

Source: https://habr.com/ru/post/897769/


All Articles