0
votes

The command is like this:

gs -q -dSAFER -dBATCH -dNOPAUSE -dPDFSETTINGS=/prepress -sDEVICE=pdfwrite -sOutputFile=output.pdf 1.pdf 2.pdf ... N.pdf

Each input PDF contains many images, and most images are shared among input PDFs.

The command runs successfully. Memory usage increases incrementally, and finally reaches 3.7GB. I have tried various PDFSETTINGS: prepress / printer / ebook / screen. The max memory did not reduce.

I want to know is it possible to reduce GhostScript memory usage? Longer CPU processing time is acceptable.

$ gs -v GPL Ghostscript 9.25 (2018-09-13) Copyright (C) 2018 Artifex Software, Inc. All rights reserved.

1

1 Answers

0
votes

No, you can't reduce the memory usage of the pdfwrite device significantly.

The pdfwrite device retains a lot of things in memory. The result of this is that for files with a huge number of pages, and many resources such as fonts, it is possible for memory usage to be extremely high.

You can't share images between PDFs. Each PDF file may contain a copy of an image which is a duplicate of an image in another PDF file, but they are not shared.

Changing PDFSETTINGS will make no real difference; this primarily affects the colour space and resolution of images, which are stored on disk, not in memory. So altering those won't change the memory usage.

Of course you could, potentially, have found a memory leak, but without seeing the input I couldn't possibly even guess. Even if you did make the input available, unless there's something trivially obvious I'm not going to try and debug something which uses better than 3GB of memory.