Any tips for speeding up GhostScript?

前端 未结 5 886
渐次进展
渐次进展 2020-12-13 00:54

I have a 100 page PDF that is about 50 MBs. I am running the script below against it and it\'s taking about 23 seconds per page. The PDF is a scan of a paper document.

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-13 01:16

    You don't say what CPU and what amount of RAM your computer is equipped with.

    Your situation is this:

    • A scanned document as PDF, sized about 500 kB per page on avarage. That means each page basically is a picture, using the scan resolution (at least 200 dpi, maybe even 600 dpi).
    • You are re-distilling it with Ghostscript, using -dPDFSETTINGS=/screen. This setting will do quite a few things to make the file size smaller. Amongst the most important are:
      1. Re-sample all (color or grayscale) images to 72dpi
      2. Convert all colors to sRGB

    Both these operations can quite "expensive" in terms of CPU and/or RAM usage.

    BTW, your setting of -dCompatibilityLevel=1.3 is not required; it's already implicitely set by -dPDFSETTINGS=/screen already.

    Try this:

    gswin32.exe ^
     -o output.pdf ^
     -sDEVICE=pdfwrite ^
     -dPDFSETTINGS=/screen ^
     -dNumRenderingThreads=2 ^
     -dMaxPatternBitmap=1000000 ^
     -c "60000000 setvmthreshold" ^
     -f input.pdf
    

    Also, if you are on a 64bit system, try to install the most recent 32bit Ghostscript version (9.00). It performs better than the 64bit version.

    Let me tell you that downsampling a 600dpi scanned page image to 72dpi usually does not take 23 seconds for me, but less than 1.

提交回复
热议问题