【发布时间】:2020-12-01 15:32:05
【问题描述】:
我无法在 php 中执行 pdftk。在文档中,它只是提到如下保存。
use mikehaertl\pdftk\Pdf;
$pdf = new Pdf('/path/my.pdf');
$pdf->allow('AllFeatures') // Change permissions
->compress($value) // Compress/Uncompress
->saveAs('new.pdf');
但是我的代码没有给出任何输出。我尝试调试像
// Check for errors
if (!$pdf->saveAs('new.pdf')) {
$error = $pdf->getError();
}
没有消息。 后来发现,pdftk没有被执行
public function saveAs($name)
{
if (!$this->getCommand()->getExecuted() && !$this->execute()) {
echo 'test'; // it is printing
return false;
}
}
这是什么意思?我是从作曲家安装的。在阅读 github 问题时,开发人员的回复可能是我的问题。是 你需要设置你的pdftk命令的路径,见https://github.com/mikehaertl/php-pdftk#execution
我不清楚如何设置路径,它没有在文档中突出显示。这里只提到了
该类使用php-shell命令来执行pdftk。您可以将其 Command 类的 $options 作为第二个参数传递给构造函数:例如。
$pdf = new Pdf('/path/my.pdf', [
'command' => '/some/other/path/to/pdftk',
// or on most Windows systems:
// 'command' => 'C:\Program Files (x86)\PDFtk\bin\pdftk.exe',
'useExec' => true, // May help on Windows systems if execution fails
]);
我正在使用 xampp。关于 pdftk,我在项目中有一个由 composer 创建的目录。 phpand这条路径是什么?这个项目可以在linux或window server中移动吗?我需要为此安装任何第三方软件吗?
【问题讨论】: