4
votes

I'm using ghostscript on a linux server to combine PDFs. I'm using the latest version, 9.05. I typically have to combine 5 or more PDFs. Currently it takes around 20 seconds to combine 3 PDFs...that just seems really slow to me. Here's the line I'm using:

gs -dBATCH -dNOPAUSE -dNOGC -q -sDEVICE=pdfwrite -sOutputFile=output.pdf -c 3000000 setvmthreshold -f a.pdf b.pdf c.pdf

Any suggestions?

4
How big are the 3 PDFs in terms of bytes and pages? How many fonts are used by each PDF? (Use pdffonts a.pdf, pdffonts b.pdf...) What are the respective facts for output.pdf? Do you know which effect -dNOGC is supposed to have? Does it work?Kurt Pfeifle
@pipitas Good point. Turning off the GC could cause more swapping. Also, needs quotes around the argument to -c option. There is no -f option.luser droog

4 Answers

2
votes

Ghostscript fully interprets each PDF file down to marking operations and then builds a new file from the combined content. This is, obviously, far slower than simply copying the content stream around. That's why what you are doing seems slow.

As suggested above, use a tool which just copies the content streams and objects, renumbering as required, this will be much faster. In addition to pdfjam (which I don't know anything about) you could also look at pdftk. There are bound to be others as well.

1
votes

If you just need to catenate some pdf's, you might check out pdfjam. I've never found it slow during catentation, but it does at times produce output pdf's that print rather slowly.

link

0
votes

Use pdfconcat, it'll do it in a split-second. Ghostscript is slow doing everything.

0
votes

After tracking down what was causing time-outs, I've noticed that Ghostscript is a lot faster dealing with pdf v1.4 (acrobat 5 compatibility) files as oppose to v1.7. Simply saving the PDF files as v1.4 speeds up when the files are later used by Ghostscript.

This may not be applicable to all situations. Depending on the speed it may be worth using Ghostscript to convert the pdf down to a lower version then other operations. I'm seeing time difference from 30+ seconds to ~1 second just by changing the pdf version.