no output file generated when using Ghostscript to convert PDF to TIFF - pdf

Here is the command I use:
gs -r300 -q -dNOPAUSE -sDevice=tiffgray -sOutputFile=sample1.tiff sample1.pdf -c quit
I don't see sample1.tiff in my current working directory. I'm running OS Mavericks.

Try running without -q so that the messages aren't suppressed, Ghostscript is probably trying to tell you what's wrong.

Related

When adding a -c option to a Ghostscript command the printer popup appears even though it has been suppressed

Consider the following ghostscript command invoked form the command line on windows.
"C:\Program Files\gs\gs9.23\bin\gswin64c.exe" -sDEVICE=mswinpr2 -dORIENT1=false -dNOPROMPT -dNOPAUSE -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dFIXEDMEDIA -dDEVICEWIDTHPOINTS=398 -dDEVICEHEIGHTPOINTS=157 -dNOPAGEPROMPT -dQUIET -dNumCopies=1 -sOutputFile="\\spool\BWLAB05" "c:\print\download\133679.pdf"
This command works great. The print comes out and there is no pop up box. Now I add the following.
-c "<</Orientation 2>>setpagedevice"
to the above command to make
"C:\Program Files\gs\gs9.23\bin\gswin64c.exe" -sDEVICE=mswinpr2 -c "<</Orientation 2>>setpagedevice" -c "quit" -dORIENT1=false -dNOPROMPT -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dFIXEDMEDIA -dDEVICEWIDTHPOINTS=398 -dDEVICEHEIGHTPOINTS=157 -dNumCopies=1 -sOutputFile="\\spool\BWLAB05" "c:\print\download\133679.pdf"
the print window appears. I have changed no other part of the command. What is causing this to happen? How can I stop the print window appearing?
The order of operands to Ghostscript is important. Especially when using the -c switch, which introduces PostScript to be executed.
Effectively you are running two commands here:
-sDEVICE=mswinpr2 -c "<</Orientation 2>>setpagedevice" -c "quit"
-dORIENT1=false -dNOPROMPT -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dFIXEDMEDIA -dDEVICEWIDTHPOINTS=398 -dDEVICEHEIGHTPOINTS=157 -dNumCopies=1 -sOutputFile="\\spool\BWLAB05" "c:\print\download\133679.pdf"
As soon as it hits the -c Ghostscript stops processing the command line, and runs the PostScript. At this point we have not yet encountered the -dNOPROMPT, and as you haven't (yet) set the printer, Ghostscript doesn't know what printer to use so , unsurprisingly, the printer popup appears.
Ghostscript carries on processing the remainder of the command line as PostScript until it reaches a -f, or in fact any switch beginning -. You haven't put a -f in there, but I would very strongly recommend that you do. You also don't need to put a secopnd -c, once you've started processing the command line as PostScript it continues, until you stop it. I also suspect that you really don't want the quit in there. That terminates the interpreter, which means the changes you've introduced via setpagedevice will be discarded, because the interpreter returns to the default state.
After processing the content of the -c, Ghostscript carries on and processes the remainder of the command line. This time there's a -dNOPROMPT so you don't get prompted.
I would expect that this:
"C:\Program Files\gs\gs9.23\bin\gswin64c.exe" -sDEVICE=mswinpr2 -dORIENT1=false -dNOPROMPT -dPrinted -dBATCH -dNOSAFER -q -dFIXEDMEDIA -dDEVICEWIDTHPOINTS=398 -dDEVICEHEIGHTPOINTS=157 -dNumCopies=1 -sOutputFile="\\spool\BWLAB05" -c "<</Orientation 2>>setpagedevice" -f "c:\print\download\133679.pdf"
would work much better. Note your initial command line has a duplicate NOPAUSE and specifies both NOPROMPT and NOPAGEPROMPT (you don't need NOPAGEPROMPT if you set NOPROMPT, and you don't need either if you set NOPAUSE).
Finally I would urge you not to use -dNOSAFER, while it currently has no effect (because that's the default setting) we will soon be making SAFER the default and setting -dNOSAFER will substantially reduce your security when running files.
You should really use -dSAFER right now. There are a number of CVEs against this, and proof of concepts circulating right now which can have undesirable effects on your computer (running arbitrary executables, opening, writing, deleting files etc) if you don't use -dSAFER. If you don't know why you want -dNOSAFER, then use -dSAFER instead.
Oh, you should also upgrade to the current version, 9.27, the version you are using is a year old.

How to merge all PDF's in a directory with ghostscript

How can I read the files contained in the directory d:\ with batchscript not one by one files like that. I have tried the following:
#echo off
"C:\Program Files\gs\gs9.25\bin\gswin32c.exe" -sDEVICE=pdfwrite -dCompatibilityLevel=1.3 -dPDFSETTINGS=/printer -dColorImageResolution=90 -dAutoRotatePages=/None -dBATCH -dNOPAUSE -sOutputFile=d:\d\koran.pdf *d:\a\01.pdf d:\a\02.pdf d:\a\03.pdf d:\a\04.pdf d:\a\05.pdf d:\a\06.pdf d:\a\07.pdf d:\a\08.pdf d:\a\09.pdf d:\a\10.pdf d:\a\11.pdf d:\a\12.pdf d:\a\13.pdf d:\a\14.pdf d:\a\15.pdf d:\a\16.pdf d:\a\17.pdf d:\a\18.pdf d:\a\19.pdf d:\a\20.pdf d:\a\21.pdf d:\a\22.pdf d:\a\23.pdf d:\a\24.pdf*
exit
Ghostscript doesn't 'merge' PDF files. It creates new PDF files by interpreting the contents of its input, this is not the same thing. You should read the documentation here
You haven't said what the problem is with the command you have tried, its going to be hard to help you if you don't do that.
The most likely problem is that you have put * characters at the start and end of the input filenames. Ghostscript itself doesn't match wildcards, it expects you to tell it each file you want to process individually. So in order to process a directory of files is to first get a list of all the files, and then tell Ghostscritp to use each of those files in turn.
You can use the Ghostscript #filename syntax (documented here)to tell Ghostscript to use the contents of a file as if it were the command line.
So all you need to do is come up with a shell script which will write the filenames from a folder into a file. That's not a Ghostscript question, and depends totally on the operating system you are using.
For Windows something like:
dir /B *.pdf >> files.txt
gswin32c -sDEVICE=pdfwrite -dBATCH -dNOPAUSE -sOutputFile=\temp\out.pdf #files.txt
del files.txt
might be sufficient for your needs.
I could not make it work using "files.txt" but I am using this and everything works just fine.
gswin64c -sDEVICE=pdfwrite -dBATCH -dNOPAUSE -sOutputFile="out.pdf" (Get-ChildItem -Path .\*.pdf)
You can execute like below:
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged.pdf *.pdf
Reference:
https://gist.github.com/moaazsidat/b94185e9cfdba9e3cfb5bc90407e6397

Why does rendering a png from this pdf using imagemagick create these streaky artifacts?

I'm running ghostscript 9.22, libpng 1.6.34, and imagemagick 7.0.7-11 Q16
Here is the command that replicates the issue:
convert -density 400 icon.pdf -scale 1024x1024 ./appicon-1024x1024.png
Here is a link to the input PDF:
https://www.pdf-archive.com/2017/12/06/icon/
Here is the output I see, with streaky horizontal line artifacts:
Interestingly, turning off antialiasing resolves the issue, but is not suitable for our use case.
I am running into this same issue and I think that Ghostscript 9.22 is the problem. I can reproduce the issue by running Ghostscript directly:
gs -dSTRICT -dDOINTERPOLATE -dNOPAUSE -dEPSCrop -dBATCH -sOutputFile=test.png -sDEVICE=pngalpha /path/to/broken.pdf
I've also tested with Ghostscript 9.21, which works as expected.
When imagemagick's convert command is run with +antialias, it passes different switches to ghostscript.
You can use the -verbose switch to tell imagemagick to print out the entire command it is using to invoke gs:
$ convert -verbose test.pdf test.png
Which yields:
'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pamcmyk32' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r72x72' -g1728x1728 -dEPSCrop ...
With the antialias flag set:
$ convert -verbose +antialias test.pdf test-with-antialias-flag.png
gives us:
'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pamcmyk32' -dTextAlphaBits=1 -dGraphicsAlphaBits=1 '-r72x72' -g1728x1728 -dEPSCrop
There are a couple of different switches set there. Based on some experimentation running gs directly, I figured out that -dGraphicsAlphaBits seems to be the culprit. If it is set to a value greater than 1, the lines appear in the output.
So there are a few potential workarounds:
Edit imagemagick's delegates.xml to force -dGraphicsAlphaBits to 1.
Install ghostscript 9.21, which seems unaffected.
Convert at double dimensions and then size down, as suggested above.
Update ghostscript to version 9.23 and reinstall imagemagick.
This command works perfectly fine for me using ImageMagick 6.9.9.25 Q16 Mac OSX and Ghostscript 9.21 and libpng #1.6.30_0.
convert -density 400 icon.pdf -scale 1024x1024 test.png
I suspect it is either your Ghostscript or libpng version. Try upgrading.

best solution for sending fax in asterisk

I want to write a script for sending a fax with Asterisk,
but many faxes have an error when sending.
I use Spandsp for Asterisk and I use gs for converting PDF to TIFF.
I think it may be a problem of converting PDF to TIFF.
I very try to convert's command for this, such as:
gs -q -sDEVICE=tiffg3 -dNOPAUSE -dBATCH -sOutputFile=Sample.pdf.tif -f Sample.pdf
/usr/bin/acroread -toPostScript -size a4 <filename>
/usr/bin/gs -q -sDEVICE=tiffg32d -sPAPERSIZE=a4 -r204x196 -sOutputFile=<outputfile> -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dNOPAUSE -dBATCH -f <inputfile.ps>
and I tested anyways into link for converting, but it doesn't work fine, and most of sending fax have issue.
Also, I have another problem in answer detection beep in my Asterisk when the trunk with Newrock gateway(analog), this is cause some fax doesn't send correctly!
Check hylafax code. It have working script
I use code like this:
gs -sDEVICE=tiffg3 -sPAPERSIZE=$pagesize -r204x196 -dNOPAUSE -dNOPAGEPROMPT -dBATCH -sOutputFile=dest.tif \
-c save pop -f input.pdf -c quit
But actualy it doesn't metter. More important how setup your routes/codecs.
Other problem is for sure offtopic here. You have read more books or hire expert.

GhostScript removes images from some processed PDF files

I'm using this command with gs 9.01:
gs -q -dAutoRotatePages=/None -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dPDFSETTINGS=/printer -sOutputFile=out.pdf in.pdf in.pdfmarks
and on some processed files (out.pdf) I noticed that images are missing, although present in input file (in.pdf).
Why is this and how can I assure that images are retained after processing with gs?
1) Update to the current version, 9.04.
2) If you still experience problems, report a bug at http://bugs.ghostscript.com. You will need to attach a sample PDF file