views:

1088

answers:

3

Greetings,

I need to programatically append to a multi-page TIFF or PDF a new image. The problem is that the individual images (that compose the multi-page one) have large resolutions and ImageMagick first loads the entire multi-page image into memory, which takes all the system's memory.

I need to be able to append to a multi-page image without having to load the entire image into memory. Is this possible with ImageMagick? Which C/C++ functions should I use?

Regards, Cosmin

+1  A: 

I'm not sure it's possible in ImageMagick.

For TIFF, what you need to do is read TIFF Directories out of one TIFF and create new ones in the one you are appending to, and then copy the encoded image via a buffer. There is no need to decode the image to do this, but you have to be careful to do it correctly and bring over any of the directories associated with the page (like the associated meta-data).

I think that libtiff (which ImageMagick wraps) provides functions that can help you do this.

For PDF, it's also hard -- this page has some alternatives:

http://ansuz.sooke.bc.ca/software/pdf-append.php

There are also many 3rd party SDKs that can manipulate PDF (ActivePDF, PDFTron, Amyuni).

Disclaimer: I work for Atalasoft: we have a .NET SDK that has this functionality for TIFF (and image-only PDF). It can be called via C++/CLI, but not sure if you are on Windows.

Lou Franco
A: 

With Imagemagicks it's quite easy to create a multi page pdf, not completly the answer to the question but the answer I was googling for... anyways... Howto convert 3 images to one 3 page PDF using imagemagicks:

convert imageForPage1.jpg imageForPage2.jpg imageForPage3.jpg resulting3Pages.pdf

Greetings, Geert

+1  A: 

I actually just struggled through this yesterday. ghostscript is much much faster to append with.

first cd into the directory that is holding the tiffs that you want to append to pdf then

$> for i in ls *.tif | sort -g; do echo -n $i" " >> list.txt; done
$> gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf $(cat list.txt)

also look at http://www.novell.com/coolsolutions/tools/17083.html

Zach Dunton