GhostScript command creates thumbnails from PDF file

I am trying to create a thumbnail image from a PDF file. I can generate a JPEG image from the command below, but the problem is that I cannot resize the output image to a fixed size (250x250)

The command -dPDFFitPage = true makes the output image fit in the given dimension, and the image is displayed as rotated. Can anyone help me fix this issue to create thumbnails for a 250x250 PDF.

/usr/bin/gs -dNOPAUSE -sDEVICE=jpeg -dFirstPage=1 -dLastPage=1 -sOutputFile=<path to output file>%d.jpeg -dJPEGQ=100 -g250x250 -dUseCropBox=true  -dPDFFitPage=true -q  <path to input file>.pdf -c quit

      

Thanks Sachin

Bug with GhostScript version 9.15

As suggested, I installed Ghostscript version 9.15. But after installation, it gives error for whatever command I passed. How to fix or check if GS is installed correctly 9.15.

 **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.
Error: /ioerror in --showpage--
Operand stack:
   1   true
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1945   1   3   %oparray_pop   1944   1   3   %oparray_pop   1928   1   3   %oparray_pop   --nostringval--   --nostringval--   2   1   1   --nostringval--   %for_pos_int_continue   --nostringval--   --nostringval--   1826   0   11   %oparray_pop   --nostringval--   --nostringval--
Dictionary stack:
   --dict:1187/1684(ro)(G)--   --dict:1/20(G)--   --dict:82/200(L)--   --dict:82/200(L)--   --dict:116/127(ro)(G)--   --dict:280/300(ro)(G)--   --dict:30/32(L)--   --dict:6/8(L)--   --dict:21/40(L)--   --dict:1/1(ro)(G)--   --dict:7/17(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 9.15: Unrecoverable error, exit code 1
Unrecoverable error: typecheck in setpagedevice

      

+3


source to share


2 answers


Below code works for me.

gs -sDEVICE = jpeg -dPDFFitPage = true -dDEVICEWIDTHPOINTS = 250 -dDEVICEHEIGHTPOINTS = 250 -sOutputFile = outputfile.jpeg inputfile.pdf



= -dDEVICEWIDTHPOINTS pixels -dDEVICEHEIGHTPOINTS = pixels

+3


source


I suspect the rotation is due to the fact that the PDF fits this path better (at smaller scaling), but I will need to see an example PDF to report.

I guess the twist is your problem. You say that you "cannot resize the output image to a fixed size (250x250)", but you say that "Command -dPDFFitPage = true makes the output image fit in the given dimension", so obviously you can resize the output ...



You should also indicate which version of Ghostscript you are using, and if you are not using the latest one (9.15) you should try that.

+1


source







All Articles