I am running ghostscript (Ghostscript 9.54.0 (2021-03-30), Arch Linux) on a ~200mb file with 270 pages like this:
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/printer -sOUTPUTFILE=out.pdf input.pdf
But ghostscript's memory usage is ballooning very fast, reaching over 32gb and crashing my machine.
Is this behaviour to be expected? It seems really excessive.
Related
I am trying to convert 1000 pages PDF document to postscript file using the below command.
gswin32c.exe -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=ps2write -sOutputFile=out.ps -f input.pdf
It takes 5 mins to convert, but in real-time, I will have more number of pages than this. I have tried with 30k pages pdf to convert ps using the same command. It takes 45mins.
After search in stack overflow, I have tried the below options of reducing resolution, set buffer memory, threading options, and all. Nothing worked. PF command below.
gswin32c.exe -q -r300 -dSAFER -dNOPAUSE -dBATCH -sDEVICE=ps2write -sOutputFile=out.ps -dNumRenderingThreads=8 -dBufferSpace=2000000000 -f input.pdf
dCompressEntireFile option also not helps. Please, anyone, suggest improving the performance of ps conversion with Ghostscript.
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.
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
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
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