简体   繁体   English

ImageMagick-将多页PDF转换为一张图像

[英]ImageMagick - convert multipage PDF into one image

I am using ImageMagick to convert PDF files into images. 我正在使用ImageMagick将PDF文件转换为图像。 However, some of the PDF's have multiple pages, which is proving to be a real problem. 但是,某些PDF具有多个页面,事实证明这是一个实际问题。

My local convert is below. 我的本地信徒在下面。

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

If i remove [$page] from the exec it works but creates an image per page, which isn't what I want. 如果我从exec中删除[$page] ,它可以工作,但每页创建一个图像,这不是我想要的。

I have been searching for a while now and i've ran out of hope and ideas. 我已经搜索了一段时间,但我的希望和想法都用光了。 Is there any way I can get all of the new images into one final image, or convert the PDF straight into one image? 有什么办法可以将所有新图像转换为一张最终图像,或者将PDF直接转换为一张图像? Any help would be greatly appreciated, cheers. 任何帮助将不胜感激,欢呼。

Check out the -append and +append options. 检出-append和+ append选项。

-append appends the images vertically, and +append appends them horizontally. -append垂直附加图像, +append水平附加图像。

Usage ( http://linuxers.org/quick-tips/convert-pdf-file-single-image-using-imagemagick ): 用法( 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: 根据该链接,多页pdf convert的输出将为$ {targetFile} -0.png,$ {targetFile} -1.png,$ {targetFile} -n.png等。转换后, pdf转换为多个图像,请使用-append或+ append选项:

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): 要将所有内容放在一起,请尝试以下类似的操作(您可能需要玩一些;我还没有使用Windows外壳程序中的Imagemagick):

// 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/script/command-line-options.php#append

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM