Convert multi page tiff file to pdf

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
kromm
Posts: 2
Joined: 2013-04-15T06:11:21-07:00
Authentication code: 6789

Convert multi page tiff file to pdf

Post by kromm »

Hello.
I'm trying to convert a multi page tiff file to pdf using Magick++. I'm using the following code:

Code: Select all

#include <Magick++.h>

int main(int argc, char **argv)
{
    Magick::InitializeMagick(argv[0]);
    Magick::Image img;
    img.read(argv[0]);
    string imageSpec = "PDF:";
    imageSpec += argv[1];
    img.write(imageSpec);
    return 0;
}
The problem is that the resulting pdf file has only one page. Example file: https://docs.google.com/file/d/0B5V7SIE ... sp=sharing
The same file is correctly converted if i use the convert tool (i.e. convert.exe input.tif output.pdf)
Since convert tool works well, i suppose my problem lies in Magick++

I'm using ImageMagick-6.8.4-9 in Windows
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Convert multi page tiff file to pdf

Post by magick »

To read a multipage PDF, use readImages().
kromm
Posts: 2
Joined: 2013-04-15T06:11:21-07:00
Authentication code: 6789

Re: Convert multi page tiff file to pdf

Post by kromm »

Thanks for the answer.
This seems to be the correct way to convert a multi page tiff to pdf:

Code: Select all

Magick::InitializeMagick(argv[0]);
std::list<Magick::Image> images; 
readImages(&images, argv[1]); 
writeImages(images.begin(), images.end(), argv[2]);
The filename in argv[2] must have a .pdf extension.
Note that this is not efficient in terms of time and memory, because it seems to load the whole file in memory and then writes it to disk.
If i come up with something more efficient i will post it here.
Post Reply