gpt4 book ai didi

php - 从 PHP : Unable to open the initial device 调用 Ghostscript

转载 作者:行者123 更新时间:2023-12-02 07:10:19 29 4
gpt4 key购买 nike

我已经从 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 中起作用。

最佳答案

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

关于php - 从 PHP : Unable to open the initial device 调用 Ghostscript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6765640/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com