ImageMagick PDF到JPG有时会导致黑色背景

时间:2012-06-07 15:02:50

标签: pdf imagemagick jpeg

我有以下内容:

ghostscript-fonts-5.50-24
ImageMagick-6.7.2-1
ghostscript-9.02-1

我使用以下方法为每个页面创建一系列JPG:

convert -density 175 -colorspace sRGB test.pdf -resize 50% -quality 95 test.jpg

当我在我的Windows机器上运行时,一切似乎都正常,但在我们的Linux服务器上,我们遇到了黑色背景问题。

生成的JPG有一个黑色背景,使图像不可读,我缺少什么,或者我应该做些什么来纠正这个?

我已经在谷歌待了几天,但每个建议似乎都不适合我。

非常感谢任何帮助,在此先感谢:)

修改

转换其中一个产生黑色背景的PDF时,注意到此输出:

**** Warning: Fonts with Subtype = /TrueType should be embedded.
             The following fonts were not embedded:
                    Arial
                    Arial,Bold
                    Arial,BoldItalic
**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> Microsoft« Word 2010 <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.

这似乎有关,但由于我们无法控制PDF的生成方式,因此我们需要一些方法来修复此服务器端。

再次感谢

3 个答案:

答案 0 :(得分:58)

今天进入这个,找到了这个:

http://www.wizards-toolkit.org/discourse-server/viewtopic.php?f=3&t=20234

基于此,这些都应该有效:

  • -flatten
  • -alpha flatten
  • -alpha remove

我目前正在使用以下内容来解决我的具体情况:

convert -thumbnail "1280x800>" -density 300 -background white -alpha remove in.pdf out.jpg

答案 1 :(得分:8)

对此问题的简单修复是使用支持透明度的图像格式,例如png。

所以:

convert -density 175 -colorspace sRGB test.pdf -resize 50% -quality 95 test.png

问题解决了:))

答案 2 :(得分:0)

如果您想要高质量的结果,请使用以下命令:

convert -density 700 input.pdf -resize 25% -append  -quality 98 -alpha remove output.jpg

对于Windows用户,请使用magick代替convert

相关问题