Sachidananda Pattnaik
Sachidananda Pattnaik

Reputation: 41

GhostScript command create thumbnail images from PDF file

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

The command -dPDFFitPage=true is making the output image to fit into the given dimension and the image is displaying as rotated. Can anyone help me fix this problem to generate the thumbnail images for a PDF file in 250x250 size.

/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

Error with GhostScript 9.15 version

As per the suggestion I have installed the Ghostscript 9.15 version.But after installing it is giving error to any command I passed. How to rectify or check if the GS 9.15 has been installed properly.

 **** 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

Upvotes: 4

Views: 5027

Answers (2)

Rajesh M. Kanojia
Rajesh M. Kanojia

Reputation: 57

The code below works for me:

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

-dDEVICEWIDTHPOINTS=pixels
-dDEVICEHEIGHTPOINTS=pixels

Upvotes: 4

KenS
KenS

Reputation: 31199

I suspect that the rotation is caused by the fact that the PDF fits better that way (less scaling involved) but I'd need to see an example of the PDF file to tell.

I'm assuming that the rotation is your problem. You say that you are "not able to resize the output image to a fixed size ( 250x250 )" but you go on to say that "The command -dPDFFitPage=true is making the output image to fit into the given dimension" so obviously you are able to resize the output.

You should also state which version of Ghostscript you are using, and if you aren't using he latest (9.15) you should try that.

Upvotes: 1

Related Questions