Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert png to pdf using ghostscript

as the title says I am trying to convert png to pdf. I could not find well described example anywhere about this.

I used this command

gs sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -sOutputFile=test.pdf test.png

but all I get is

Error: /syntaxerror in (binary token, type=137)
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1894   1   3   %oparray_pop   1893   1   3   %oparray_pop   1877   1   3   %oparray_pop   1771   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push
Dictionary stack:
   --dict:1161/1684(ro)(G)--   --dict:0/20(G)--   --dict:77/200(L)--
Current allocation mode is local
GPL Ghostscript 9.07: Unrecoverable error, exit code 1

this error message. And now I started wodering if such feature is possible in ghostscript. Should I use other software? ** I'm runing the latest 9.07 version

like image 868
Eugene Yu Avatar asked Dec 10 '13 00:12

Eugene Yu


People also ask

How do I convert from PNG to PDF?

How to convert PNG to PDF. It's easy — simply go to Adobe Acrobat online services from any web browser and navigate to the convert JPG to PDF page. Click the Select A File button or drag and drop the image file into the drop zone to upload.

Why use GhostScript?

Ghostscript can be used as a raster image processor (RIP) for raster computer printers—for instance, as an input filter of line printer daemon—or as the RIP engine behind PostScript and PDF viewers. It can also be used as a file format converter, such as PostScript to PDF converter.

Do I need GhostScript?

A designated version of GhostScript is only required if you want to save your output files in PostScript format. Advanced users can do the same using command line utility in manual, automated or scheduled mode.

How do I convert PDF to JPG in Linux?

Click the "Open File" option or use the "File → Open" menu to import the PDF into the software. Step 2. Next, click on "File → Export To → Image → JPEG (. jpg)".


2 Answers

Ghostscript can output multiple formats (png included) but I don't believe it is able to take png as an input. You may be able to accomplish your goal using something like imagemagick's convert utility, though: convert test.png test.pdf

like image 129
oakad Avatar answered Oct 20 '22 22:10

oakad


Yes, image magick can do this no problem - here's the cmd line for looping through all the pngs in a folder and converting to pdf:

cd to the folder with the pngs

mogrify -format pdf -density 300 -units PixelsPerInch *png

like image 24
mike Avatar answered Oct 20 '22 21:10

mike