Convert Multipage PDF to a Single Image

Convert multipage PDF to a single image

Finally I find THE solution:

convert in.pdf -append out%d.png

Thanks to this post.

edit

As a plus, the opposite operation is:

convert *.png output.pdf

or if you have foo1.png, foo2.png..fooN.png

convert foo?.png output.pdf

Notice that does not work with foo01.png, foo02.png..foo0N.png

Converting a multiple-page PDF to a single image

Did you have a look at ImageMagick? This free library might have an option to create a single image from a PDF (It actually uses Ghostscript but adds a lot of graphical editing capabilities such as merging images).

ImageMagick - convert multipage PDF into one image

Check out the -append and +append options.

-append appends the images vertically, and +append appends them horizontally.

Usage (http://linuxers.org/quick-tips/convert-pdf-file-single-image-using-imagemagick):

According to that link, the output from a multi-page pdf convert would be ${targetFile}-0.png, ${targetFile}-1.png, ${targetFile}-n.png, etc. Once you have converted the pdf into multiple images, use the -append or +append option:

convert ${targetFile}-* -append single_image.png

To put it all together, try something like this (you may have to play with it a bit; I haven't used Imagemagick from the Windows' shell):

// convert pages of pdf

exec("\"C:\\Program Files (x86)\\ImageMagick-6.8.5-Q16\\convert.exe\" -density 300 -quality 75 \"{$path}{$filename}{$ext}\" \"{$targetFile}\"");

// then append them

exec("\"C:\\Program Files (x86)\\ImageMagick-6.8.5-Q16\\convert.exe\" \"{$targetFile}-*\" -append "${someName}\"");

More resources:

http://www.imagemagick.org/script/command-line-options.php#append

http://www.imagemagick.org/Usage/layers/

How can I converting multi page PDF file to many images .jpeg with Vips in C++?

I found a way to solve this using crop.

    VImage in = VImage().pdfload("/Users/MyUser/Desktop/PDF_Reader/files/TEST_DOC_READER.pdf", voptions);
pages = in.get_int("n-pages");
h = in.height()/pages;

for(int i=0; i<pages; i++){
in.crop(0,i*h, in.width(), h).jpegsave((outdir+to_string(i)+format).c_str());
}

How do I convert a multiple paged PDF into a PNG image per pdf page in Python

Your code is only outputting a single file as far as I can see. The problem is that you have a typo in your code.

The line

file_number =+ 1

is actually an assignment:

file_number = (+1)

This should probably be

file_number += 1



Related Topics



Leave a reply



Submit