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

jhd*_*vuk 37 pdf jpeg imagemagick

我有以下内容:

ghostscript-fonts-5.50-24
ImageMagick-6.7.2-1
ghostscript-9.02-1
Run Code Online (Sandbox Code Playgroud)

我用它为每个页面创建一系列JPG:

convert -density 175 -colorspace sRGB test.pdf -resize 50% -quality 95 test.jpg
Run Code Online (Sandbox Code Playgroud)

当我在我的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.
Run Code Online (Sandbox Code Playgroud)

这看起来很相关,但由于我们无法控制PDF的生成方式,因此我们需要一些方法来修复此服务器端.

再次感谢

Tap*_*nen 66

今天进入这个,发现这个:

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
Run Code Online (Sandbox Code Playgroud)

  • 如果你想将多页PDF分成每页几个JPEG,`-flatten`将不起作用,因为它会将所有页面混合成一个单独的图像.`-alpha flatten`或`-alpha remove`是要走的路. (7认同)
  • 对于C#,您可以使用:image.Alpha(AlphaOption.Remove); (2认同)

jhd*_*vuk 8

解决此问题的简单方法是使用支持透明度的图像格式,例如png.

所以:

convert -density 175 -colorspace sRGB test.pdf -resize 50% -quality 95 test.png
Run Code Online (Sandbox Code Playgroud)

问题解决了 :)