【发布时间】:2011-07-20 17:02:08
【问题描述】:
我已经从 MacPorts 安装了 Ghostscript,并试图从 PHP 脚本中调用它以从多页 PDF 文件中提取单页,然后将其输出。我的代码如下所示:
<?php
$cmd = '/opt/local/bin/gs -sDEVICE=pdfwrite -dNOPAUSE \
-dBATCH -dSAFER -dFirstPage=20 -dLastPage=20
-sOutputFile=%stdout "/path/to/input/pdf.pdf"';
// Will uncomment this when it works
// header("Content-Type: application/pdf");
putenv("GS_LIB=/opt/local/share/ghostscript/9.02/lib");
putenv("GS_FONTPATH=/opt/local/share/ghostscript/fonts");
putenv("TMPDIR=/tmp");
passthru($cmd);
当我在网络浏览器中点击此脚本时,我看到:
GPL Ghostscript 9.02 (2011-03-30) Copyright (C) 2010 Artifex Software, Inc.
All rights reserved. This software comes with NO WARRANTY: see the file
PUBLIC for details. **** Unable to open the initial device, quitting.
同样的命令可以在 shell 中运行。
【问题讨论】:
标签: php ghostscript