5

I have 280 pgn files that I want to merge and convert into one pdf.

PNG files names are in the sequence p000.png, p001.png etc and total space is about 30mb.

I did:

convert p00*.png to myfile.pdf 

and it worked fine. Luckly enough in the right order.

But when I do:

conver p*.png to myfile.pdf

It consumes all my 4Gb of memory and half my swap. Then it crashes with the error

convert: memory allocation failed `myfile.pdf' @ error/pdf.c/WritePDFImage/1595.

Any idea of how to make a workaround to this problem?

I think that a good enough solution would be to use convert one file at a time to pdf, with the same name. Then use pdfunite or pdftk to merge them. But I don't know how to use convert in this way.

1
  • You could just use pdflatex to place all the pngs on one pdf. More infos are on TeX.SX. Feb 20, 2013 at 22:06

1 Answer 1

8

Imagemagick seems to be very violent with memory usage. A suggestion is to use -limit to limit the memory size convert will use, it should use a disk cache for anything else it needs. Read an explanation here:

http://www.imagemagick.org/pipermail/magick-users/2002-March/001285.html

And here's how to use the -limit option : http://www.imagemagick.org/script/command-line-options.php#limit

If not, you can do it like you describe, converting each image individually and then merging them with some other tool. Something like

for name in p*.png; do convert $name `basename $name .png`.pdf; done

should do it.

Basically it iterates over all the png files, runs convert on them, the only magic is the basename $name .png part, which will be replaced by the filename minus the .png part, so that when attaching .pdf extension to it, the filename makes sense.

Try it for yourself so you get a feel of what basename does:

basename something.png .png
echo `basename something.png .png`.pdf
1
  • I had to play around with the limit option and it finally worked with "-limit memory 128MiB -limit map 256MiB". Also "basename" was a cool thing to learn. Thanks
    – Presbitero
    Feb 20, 2013 at 1:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .