从PHP调用Ghostscript:无法打开初始设备

ale*_*ntd 2 php ghostscript

我已经从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);
Run Code Online (Sandbox Code Playgroud)

当我在网络浏览器中点击此脚本时,我看到:

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

相同的命令来自shell.

pro*_*php 5

apache/webserver用户可能没有权限或相同的环境变量.也许尝试sudo,或确保apache具有适当的权限.