【发布时间】:2023-03-28 09:30:01
【问题描述】:
我想问是否可以使用 PHP 从我已经知道密码的受密码保护的 PDF 文件中删除密码?我见过this page,它提供了许多选项,但使用的是 bash 脚本。 :( 我被要求尽可能多地使用 PHP。任何建议表示赞赏!
【问题讨论】:
-
你可以在java的帮助下找到我的答案stackoverflow.com/questions/29530714/…
我想问是否可以使用 PHP 从我已经知道密码的受密码保护的 PDF 文件中删除密码?我见过this page,它提供了许多选项,但使用的是 bash 脚本。 :( 我被要求尽可能多地使用 PHP。任何建议表示赞赏!
【问题讨论】:
当然有可能,您只需对加密和压缩进行逆向工程,并在 PHP 中实现逆向操作 - 但何必费心呢:
<?php
`gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=unencrypted.pdf -c .setpdfwrite -f encrypted.pdf`;
?>
C.
【讨论】:
-sPDFPassword=yourpassword。
我在 linux 上使用qpdf 来删除 pdf 密码。安装运行:
sudo apt install qpdf
这是从 php 调用 qpdf 的函数:
function removePdfPassword($inFilePath, $password, $outFilePath)
{
if (empty($inFilePath) || empty($password) || !file_exists($inFilePath)) {
return false;
}
$cmd = 'qpdf -password=' . escapeshellarg($password) . ' -decrypt ' . escapeshellarg($inFilePath) . ' ' . escapeshellarg($outFilePath);
exec($cmd, $output, $retcode);
$success = $retcode == 0;
if (!$success) {
@unlink($outFilePath);
}
return $success;
}
【讨论】: