PDF to PNG conversion using Ghostscript: only the fist page is in the output PNG file - windows

I am using Ghostscript on Windows 7 machine to convert PDF to PNG. My input PDF has many pages but the PNG file only contain the first page !
I am using the following command line:
gswin64c -sDEVICE=png16m -r720x720 -dNOPAUSE -dBATCH -sOutputFile=79245340005_1602.png 79245340005_1602.pdf
and the logfile is as follow:
GPL Ghostscript 9.20 (2016-09-26)
Copyright (C) 2016 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 2.
Page 1
Page 2
As you can see, it seems that both pages are processed but only the first one appear in the final PNG file. Any idea what is wrong in my command line ? I try to look a the documentation but didn't find what I am doing wrong. If I have a single PDF file with 10 pages, I wand a single output PNG file with 10 pages.
My original command line was as follow but had the same issue:
gswin64c -q -sPAPERSIZE=a4 -sDEVICE=png16m -dTextAlphaBits=4 -r720x720 -o 79245340005_1602.png -dNOPAUSE -dBATCH 79245340005_1602.pdf
Thanks
Fabien

PNG can hold only one image per file. Use TIFF or the like for multiple images per file.

Try to use following syntax to achieve rasterizing into several png's
gswin64c -q -sPAPERSIZE=a4 -sDEVICE=png16m -dTextAlphaBits=4 -r720x720 -o -sOutputFile='79245340005_1602_%00d.png' -dNOPAUSE -dBATCH 79245340005_1602.pdf

Related

GhostScript generating damaged tiff file

I am trying to generate tiff file using ghost script from a pdf.
I am using this command
gs -dSAFER -dBATCH -dNOPAUSE -dFirstPage=2 -dLastPage=2 -r450x635 -sDEVICE=tiffgray -sCompression=lzw -sOutputFile=test2_local.tif foil.pdf
The tiff file is getting generated but it is not opening and i am getting message of damaged file. If I reduce resolution then it works fine. And it also works if remove the compression.
But i can not remove compression as file size generated is 174MB. I am using GS 9.22 on mac OS.

Ghostscript 9.14 - Create PDFA from PS

I have a requirement of creating PDFA Document from PS in my LINUX environment.
I am using the following command line to generate the same:
gs -q -dPDFA=2 -sColorConversionStrategy=/RGB -dBATCH -dPDFSETTINGS=/screen -dNOPAUSE -dNOOUTERSAVE -sProcessColorModel=DeviceRGB -sDEVICE=pdfwrite -sOutputFile=pdfA_New.pdf /project/mgos/9.14/lib/PDFA_def.ps Sample.ps
I am able to create PDFA Document however the Standards show the following:
1. Standard:PDF/A-2B . This should be 2U for me.
Also the Output Intent data is missing.
Let me know if I am missing anything.
Thanks,
Arun
Ghostscript doesn't support PDF/A-2U at all, just PDF/A-2b. I really really don't recommend use of PDFSETTINGS if you plan to request PDF/A output.
And you should upgrade to Ghostscript 9.15 as well.

ghostscript convert pdf to pcl with wrong orientation

I have an issue trying to convert a pdf document to a pcl document using Ghostscript.
The original pdf document is landscape and so the pcl should be as well. Nevertheless in windows using Ghostscript 9.14 with the following command functions:
gswin32 -dNOPAUSE -dBATCH -sDEVICE=ljet4 -dSAFER -dAutoRotatePages=/NONE -sPAPERSIZE=a4 -sOutputFile=./convert_windows.pcl ./duplicate_windows.pdf
The same command in Ubuntu Linux Kernel Version 3.2.0-40-generic 64 bit - but with Ghostscript 9.05 - results in a wrong orienteated pcl file of size A3 instead of A4 as the original.
The original pdf file contains windows font "arial", which should be available in linux as well. The package "msttorcefonts" is installed on linux. This is an short extract of the fontmap of Ghostscript:
cat /usr/share/ghostscript/9.05/Resource/Init/Fontmap.GS
gives:
% This font, and only this font among the Hershey fonts, uses
% the SymbolEncoding.
/Hershey-Symbol (hrsyr.gsf) ; % 5066567
/Arial /ArialMT ;
/Arial,Bold /Arial-BoldMT ;
/Arial,Italic /Arial-ItalicMT ;
/Arial,BoldItalic /Arial-BoldItalicMT ;
The following listing shows the output of the linux command line, which is the same output as from the windows Ghostscript console!
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 2.
Page 1
Loading NimbusMonL-Bold font from /usr/share/fonts/type1/gsfonts/n022004l.pfb... 3627296 2211468 1767360 473754 3 done.
Loading NimbusSanL-Bold font from /usr/share/fonts/type1/gsfonts/n019004l.pfb... 3668288 2319461 1807728 497748 3 done.
Loading NimbusSanL-Regu font from /usr/share/fonts/type1/gsfonts/n019003l.pfb... 3800176 2466391 1827912 512832 3 done.
Loading NimbusMonL-Regu font from /usr/share/fonts/type1/gsfonts/n022003l.pfb... 3964224 2617715 1969200 654805 3 done.
Page 2
I alredy tried several options of Ghostscript like
-dFIXEDMEDIA
-dNORAGEPAGESIZE
and others.
When converting the pdf document to ps the result is the same on both environments.
Does anyone has experiences with that issue or an idea?
Thanks in advance and kind regards
Its unlikely anyone can help at all without seeing teh original PDF file, so I would suggest that you open a bug report and attach the PDF file there.
A few observations:
-dAutoRotatePages only has an effect when creating a PDF file, not when interpreting one.
The switch -dFIXMEDIA should be -dFIXEDMEDIA, likewise NORAGEPAGESIZE should be NORANGEPAGESIZE
This may be a possible solution, which works in my case. Precondition: Ghostscript Version 8.6.0 or higher!
Converting pdf to ps not with gs command, but with gs wrapper pdf2ps, which is part of the ghostscript package:
pdf2ps input.pdf output.ps
BUT: For landscape pdf documents this works only since version 8.60 or higher! Otherwise landscape documents will be printed in portrait.
Converting pdf to pcl worked for me using the following command:
gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=ljet4 -sPAPERSIZE=a4 -sOutputFile=output.pcl -c "<< /InputAttributes << currentpagedevice /InputAttributes get { pop null } forall >> dup 0 << /PageSize [ 595 842 ] >> put >> setpagedevice" save pop -f input.pdf
BUT: This command is based on the documentation of Bug Bug 689919 of ghostscript (refer to http://bugs.ghostscript.com/show_bug.cgi?id=689919) and works for portrait-orientated documents only if you have installed a version 8.60 or higher. Because I have three different environments I can approve, that this command works since version 8.60. I used Versions 8.16, 8.62 and 9.05.
For versions 8.62 and 9.05 of ghostscript both commands worked properly for pdf --> ps and pdf --> pcl for landscape and portrait.

ImageMagick Errors: Convert PDF to Images

When I run the following command to convert a PDF to Image using ImageMagic Convert util with the following parameters :
C:\Windows\system32>"C:\Program Files\ImageMagick-6.5.8-Q16\convert.exe" "D:\RealDocs.pptx.pdf" "d:\hello.jpg"
I get the following error :
convert.exe: `%s': %s "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" "-sOutputFile=C:/Users/Nupitch/AppData/Local/Temp/magick-xwOF7jbV" "-fC:/Users/Nupitch/AppData/Local/Temp/magick-BescEsek" "-fC:/Users/Nupitch/AppData/Local/Temp/magick-XfLll9WM" # utility.c/SystemCommand/1964.convert.exe: Postscript delegate failed `D:\RealDocs.pptx.pdf': No such file ordirectory # pdf.c/ReadPDFImage/634.convert.exe: missing an image filename `d:\hello.jpg' # convert.c/ConvertImageCommand/2838.
please help me ~
ImageMagick cannot handle PostScript and PDF files itself and by its own. For this it uses a third party software called Ghostscript as a 'delegate'.
Has your Windows system Ghostscript installed properly? Or is not installed at all?
Try to download and install the latest version from here.
Probably you'd get a different error message if the problem is caused by a missing Ghostscript installation. But your error is:
D:\RealDocs.pptx.pdf': No such file or directory
# pdf.c/ReadPDFImage/634.convert.exe: missing an image filename `d:\hello.jpg'
This could mean that the user account you run this command under does not have permission to write to the root of the D: drive.
To test this, you could run the conversion command in a cmd.exe window in a slightly modified way:
"C:\Program Files\ImageMagick-6.5.8-Q16\convert.exe" ^
"D:\RealDocs.pptx.pdf" ^
"%userprofile%\hello.jpg"
(On Windows XP, %userprofile% usually points to c:\documents and settings\<your username>\...)

How to get a LZW tiff with 24 bit depth from pdf file using Ghostscript

I am using Ghostscript9.0, I try to generate a LZW TIFF images with 24 bit depth from pdf file, I always get bit depth = 1 using this GS command:
gswin32.exe -dSAFER -dBATCH -dNOPAUSE -r200 -sDEVICE=tifflzw -sOutputFile=tmp.tiff myfile.pdf
I searched in several manuals:
http://ghostscript.com/doc/current/Devices.htm
http://www.ghostscript.com/doc/8.54/Use.htm
but I didn't find anything of parameters to do that.
I add an image example proporties that I would like to produce with gs:
Here we can see the bit depth (profondeur de couleur) = 24 and the image is compressed with LZW
It is clearly stated that the format tifflzw you have chosen is located in the section
The remaining TIFF drivers all
produce black-and-white output with
different compression modes
http://ghostscript.com/doc/current/Devices.htm
If you want a 24bit output you have to use tiff24nc instead and add specify the compression via the parameter -sCompression=lzw
gswin32.exe -dSAFER -dBATCH -dNOPAUSE -r200 -sDEVICE=tiff24nc -sCompression=lzw -sOutputFile=tmp.tiff myfile.pdf

Resources