1

I am trying to convert jpg images to PDF using GhostScript. I have installed latest version on ghostscript on my Win7 32bit machine.

gswin32c -sDEVICE=pdfwrite -h -r300  -o C:\Docs\MyFile.pdf  
C:\gs\gs9.10\lib\viewjpeg.ps -c C:\Docs\123.jpg viewJPEG

It read and created pdf but it is of size 3KB which doesnt show anything in it.

Is something wrong with the above command?

Solved:

I used following command and it converted my jpeg to PDF

gswin32c -sDEVICE=pdfwrite -o stuff%03d.pdf viewjpeg.ps -c "(C:/Docs/grid.jpg) << /PageSize 2 index viewJPEGgetsize 2 array astore  >> setpagedevice viewJPEG"

1 Answer 1

2

Yes the command is invalid. -h gives you help at the command line, its not sensible to use that in a real command. You've specified -c which means 'process the next stuff as direct PostScript' and then put the filename directly. '\' is an escape character in PostScript, so you'll end up trying to execute a PostScript command 'CDocs123.jpg' there won't be any such command, so you'll get an error. The pdfwrite device has already opened the PDF file, but the error means no marks are drawn on the page, so you get an empty PDF file.

You need to enclose the filename in parentheses so that it is loaded as a PostScript string, and I'd also recommend using forward slashes:

(c:/Docs/123.jpg)

3
  • Thanks for you input. I tried with following command gswin32c -sDEVICE=pdfwrite -r300 -o (C:/Docs/MyFile.pdf) C:/gs/gs9.10/lib/viewjpeg.ps -c (C:/Docs/123.jpg) viewJPEG but it gave error "Unable to open initial device, quitting"
    – arya009
    Sep 19, 2013 at 8:11
  • sorry my mistake. I chose wrong file ie. 123.jpg which didnt exists. Now it created file after i issued following command `gswin32c -sDEVICE=pdfwrite -r300 -sOutputFile=MyFile-%d.pdf C:/gs/gs9.10/lib/viewjpeg.ps -c (C:/Docs/grid.jpg) viewJPEG quit' but The image is aligned at bottom of the page in the pdf. is there anyway to align it to top?
    – arya009
    Sep 19, 2013 at 8:28
  • I think this was answered on IRC.
    – KenS
    Sep 19, 2013 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.