imagemagick FailedToExecuteCommand `"gswin64c.exe" when converting pdf - pdf

I am seeing the following error when converting a pdf into another pdf just as a test. This also happens when converting the pdf into any other file format
magick convert example.pdf test.pdf
convert: FailedToExecuteCommand `"gswin64c.exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -dPrinted=false "-sOutputFile=C:/Users/brand/AppData/Local/Temp/magick-MzUgEU_V-cMidHdNrWG2hR56GHegabIj%d" "-fC:/Users/brand/AppData/Local/Temp/magick-ip4WYomlHXJDe5oZnT8WnJ3S-c6NgSe2" "-fC:/Users/brand/AppData/Local/Temp/magick-U7oHzpaPP3SMSPujfBR1lS8_QXa3KII0"' (The system cannot find the file specified.
) # error/delegate.c/ExternalDelegateCommand/516.
convert: PDFDelegateFailed `The system cannot find the file specified.
' # error/pdf.c/ReadPDFImage/714.
convert: no images defined `test.pdf' # error/convert.c/ConvertImageCommand/3327.
I have installed imagemagick on windows.
Converting from .png or .jpg to .pdf seems to work but converting from .pdf to any other file format doesn't seem to work.

Installing GhostScript did the trick. Kudos to K J

Related

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.

Ghostscript command convert pdf into large JPGE File

I have a ghostscript command that converts a pdf into several JPG images (one for every page). The command arguments are as follows:
-q -dUseCropBox -dFirstPage=1 -dLastPage=1 -dBATCH -dDOINTERPOLATE -dNOPAUSE -dSAFER -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dPrinted=false -r250 -sDEVICE=jpeg -dJPEGQ=100 -sOutputFile=output.jpg input.pdf -c quit
The pdf size is 1.5mb but in the JPGE images it becomes huge (~15MB) with dimension 8829 *15551
if I change the resolution in the ghostscript command to -r150 the page size is correct but the image quality is very rastorized.
Is there another way to decrease the image size of the image without affecting the image quality?
Thanks

How to set the physical size of PDF pages with Ghostscript?

I want to convert a bunch of .eps images to a single PDF using Ghostscript.
But when I look at the PDF file in a PDF viewer and set view to 100% to physical size of the file is huge!
I would like to force gs to create the PDF in letter size, but everything I tried failed.
Here's the command I'm using:
gs -dBATCH -dNOPAUSE -dEPSFitPage -dEPSCrop \
-q -sDEVICE=pdfwrite -sOutputFile=out.pdf \
file1.eps file2.eps
All my attempts with -sPAPERSIZE=legal and -dDEVICEWIDTHPOINTS=w -dDEVICEHEIGHTPOINTS=h had no effect.
-dEPSFitPage and -dEPSCrop are mutually exclusive. Try getting rid of the -dEPSCrop and putting back -sPAPERSIZE=legal. If that doesn't work, it is probably because the .eps file is over-riding the media, so try adding -dFIXEDMEDIA.
BTW, this answer is cribbed from:
Fit to page size in ghostscript (with a possibly corrupt input)
The problem was -dEPSFitPage it was fitting the page size to the .eps file size... using -dPDFFitPage (and skipping the mutually exclusive -dEPSCrop) solved my problem.
gs -dBATCH -dNOPAUSE -sPAPERSIZE=letter \
-dPDFFitPage -q -sDEVICE=pdfwrite \
-sOutputFile=out.pdf \
file1.eps file2.eps

Converting PDF to PCL via Ghostscript only without colour?

We are trying to convert some PDF files into PCL files using Ghostscript.
The commandline we're using:
gswin32c -dBATCH -dNOPAUSE -sDEVICE=pxlcolor \
-f ..\examples\pu.pdf -sOutputFile=..\examples\pu.pcl
This generates a black&white PCL file.
Please help, what's wrong?

Remove PDF margins while using PDFFitPage in GhostScript

I'm fitting a file with no margins (produced using a pdfcrop from a normal PDF file) to a given paper size using GhostScript:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dFIXEDMEDIA \
-dPDFFitPage -d -dBATCH -dQUIET -dNOPAUSE -dDEVICEWIDTHPOINTS=864 \
-dDEVICEHEIGHTPOINTS=612 -sOutputFile=$INPUT $OUTPUT
but the output has additional margins (I was cropping in order to get rid of them).
Is it possible to force GhostScript to produce output without these margins?
Without seeing your file I cannot be certain, however I suspect that all you have done is set a /CropBox in the PDF file. By default Ghostscript uses the /MediaBox which is probably unchanged.
Try setting -dUseCropBox