首页 > 解决方案 > 使用 imagick 去除 pdf 文件中的注释

问题描述

我使用imagick将pdf翻译成jpg;

但由于 pdf 文件中存在注释,它返回黑色区域,当我将图片悬停在 pdf 文件中时,会出现注释

图像文件:

在此处输入图像描述

原始pdf示例:

在此处输入图像描述

我的代码:

$img = new Imagick('./pige.pdf[1]');
$img->setImageBackgroundColor('white');

$img = $img->flattenImages();

$img->setImageFormat('jpg');
$img->writeImage('image.jpg');

标签: phppdfimagemagickimagick

解决方案


所以我的解决方案是使用 imagick 更改默认安装的 gs :

这似乎是默认情况下与 ImageMagick 一起安装的 ghostscript 版本中的一个错误。Ghostscript 是实际执行从 pdf 到渲染位图的转换的程序。

我尝试了从以下网址下载的最新版本的 Ghostscript:https ://www.ghostscript.com/download/gsdnld.html

使用命令行转换 PDF:

gs-9540-linux-x86_64 -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r72x72' '-sOutputFile=/var/app/bugs/bug389/gs_output.png' '-f/var/app/bugs/bug389/pige.pdf'

它似乎工作正常。

我想如果你:


推荐阅读