多个图片合并到pdf

用Imagemagick的convert命令转换pdf为图片

Previously, I have talked about how to convert PDF to images using pdftoppm here. In this post, I want to share how to accomplish this task with Imagemagick.

Imagemagick provides the convert tool that can be used to do various complicated image processing tasks.

Convert All Pages of PDF File to Images
Use convert to convert PDF pages to images with the following command:
英文不好的话直接看这里,一条命令:
convert -density 150 presentation.pdf -quality 90 output-%3d.jpg
解释一下,density 150 是dpi的分辨率,-quality 就是90%的质量。 输出如果想1.jpg 2.jpg 3.jpg 。。。,那就是%d ,3就是几位数的意思。
In the above command, we convert all the pages of the PDF files to images. -density is used to specify the DPI of the output images. For PDF files, it must be the first option since PDF files has no notion of DPI. This option must be used first so that convert know how to sample the PDF pages. -quality specify the quality for the generated images. %3d is used to specify the format for generated image names. The generated images will be named output-001.jpg, output-002.jpg ……

Convert Single Page of PDF File to Image
To convert a single page of PDF to image, use the following command:
如果是单页的pdf,就是下面命令:
convert -density 150 presentation.pdf[0] -quality 90 test.jpg
The number inside the bracket is used to select a page. Note that the page index starts at 0 instead of 1.

To resize the converted image, you can supply the -resize option:
要想缩小图片50%,就是这样:
convert -density 150 presentation.pdf[0] -quality 90 -resize 50% test.jpg
Convert A Range of PDF Pages to Images
You can also specify a range of pages with the following command:
只取前5页:
# convert from page 0 to page 5
convert -density 150 presentation.pdf[0-5] -quality 90 test.jpg