如何使用 ImageMagick、Ghostscript、Windows Vista/7 x64 安装、测试、转换、调整 PDF 大小 [英] How to install, test, convert, resize PDF using ImageMagick, Ghostscript, Windows Vista/7 x64

查看:39
本文介绍了如何使用 ImageMagick、Ghostscript、Windows Vista/7 x64 安装、测试、转换、调整 PDF 大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在让 ImageMagick 和 Ghostscript 协同工作时遇到问题 - 从安装到测试,再到实际使用该软件,一切似乎都很困难.有人有什么建议吗?

I'm having trouble with getting ImageMagick and Ghostscript to work together - everything seems difficult, from installation, to testing, to actually using the software. Does anyone have any tips?

推荐答案

在过去的三个小时里,我刚刚花了三个小时让 ImageMagick 与 PHP 完美结合,将 PDF 转换为 JPG.与其自己在本地记录,我想我应该把它写在这里,把所有的流行语和我搞砸的东西都写在这里,这样下一个菜鸟可以节省一些时间.

I've just spent the last three hours getting ImageMagick to play nicely with PHP for a PDF to JPG convert. Instead of documenting it myself locally, I figured I'd write it up here, with all the buzzwords and things I screwed up, so the next noob can save some time.

在两个操作系统上进行测试,Windows 7 x64 和 Vista x64,使用 PHP 5.2.8 和 Apache 2.2.11.

Tested on two OSs,Windows 7 x64 and Vista x64, with PHP 5.2.8 and Apache 2.2.11.

您需要 Ghostscript 和 ImageMagick.我得到了 gs871w64.exeImageMagick-6.6.3-0-Q16-windows-x64-dll.exe.

You'll need Ghostscript and ImageMagick. I got gs871w64.exe and ImageMagick-6.6.3-0-Q16-windows-x64-dll.exe.

对 ImageMagick 进行基本安装(我现在称其为 IM).仔细检查系统路径变量以确保您可以从任何地方进行 IM.它应该指向 IM 目录.使用 cmd 中的这一行测试安装:convert test.gif test.jpg(假设您有 test.gif).工作正常.

Do a basic install of ImageMagick (I'll call it IM now). Double check the system path variable to ensure you can IM from anywhere. It should point to the IM directory. Test the installation with this line in cmd: convert test.gif test.jpg (assuming you have test.gif). Works OK.

测试 PDF 转换(convert test.pdf test.jpg).您应该收到关于gswin32c.exe"和Postscript 委托失败"和缺少图像文件名"的(长)消息.这意味着 IM 找不到 PDF翻译器".你需要 Ghostscript.

Test a PDF convert (convert test.pdf test.jpg). You should get a (long) message about "gswin32c.exe" and "Postscript delegate failed" and "missing an image filename". That means IM can't find a PDF 'translator'. You need Ghostscript.

安装 Ghostscript(我现在称它为 GS).由于某种原因,我不得不这样做两次.将 GS 文件夹中的bin"地址添加到系统变量中.使用 gswin32 test.pdf 测试安装,您应该会在 GS 查看器中看到您的文件弹出.重要说明:gs 在 Windows 中不起作用('gs' 不被识别为内部或外部命令、可运行的程序或批处理文件.).您需要使用 gswin32.

Install Ghostscript (I'll call it GS now). I had to do it twice for some reason before it took. Add the 'bin' address in the GS folder to the system variable. Test the installation with gswin32 test.pdf and you should see your file pop up in the GS viewer. Important note: gs doesn't work in Windows ('gs' is not recognized as an internal or external command, operable program, or batch file.). You need to use gswin32.

回到 IM 测试:convert test.pdf test.jpg 现在应该可以工作了.

Back to the IM test: convert test.pdf test.jpg should work now.

现在转到 PHP - 编写此脚本:

Now over to PHP - write up this script:

$out = shell_exec("convert blah.pdf blah2.jpg 2>&1");
echo $out;

2>&1 将移动所有错误进入标准输出,以便您可以更好地诊断内容:).现在,您的 PHP 脚本可能会在 cmd 提示符下运行,但在浏览器中运行时没有任何反应.拍拍额头,重启Apache.

The 2>&1 will move all errors into the standard output so you can better diagnose stuff :). Now, your PHP script may run in the cmd prompt, but nothing happens when you run it in a browser. Smack your forehead and restart Apache.

pant 详尽无遗,可能很初级,我知道.但是,大约 20 页的半有用线索的总结很有帮助.

pant Exhaustive and probably elementary, I know. But a hopefully helpful summary of approximately 20 pages of semi-helpful clues.

这篇关于如何使用 ImageMagick、Ghostscript、Windows Vista/7 x64 安装、测试、转换、调整 PDF 大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆