lpuissantberger/fpdi-protection

此软件包最新版本(1.1.2)没有提供许可信息。

Setasign FPDI-Protection 的 Composer 版本

1.1.2 2018-04-13 13:41 UTC

This package is not auto-updated.

Last update: 2024-09-22 04:24:30 UTC


README

Setasign FPDI-Protection 和 FPDF Protection 脚本的 Composer 版本

此脚本可以保护 PDF 文件,即阻止人们复制其内容、打印或修改它。

安装

composer require lpuissantberger/fpdi-protection

用法

SetProtection([array permissions [, string user_pass [, string owner_pass]]])
  • 权限:权限集合。默认为空(仅允许查看)。
  • 用户密码:用户密码。默认为空。
  • 所有者密码:所有者密码。如未指定,将使用随机值。

权限

权限数组包含以下列表中的值

  • FPDI_Protection::CAN_PRINT:打印文档
  • FPDI_Protection::CAN_MODIFY:修改它(除注释和表单外)
  • FPDI_Protection::CAN_COPY:复制文本和图像到剪贴板
  • FPDI_Protection::CAN_ANNOT_FORMS:添加注释和表单

示例

$src_file = 'source.pdf';
$dest_file = 'protected.pdf';

$pdf = new \FPDI_Protection();
$pagecount = $pdf->setSourceFile($src_file);

for ($loop = 1; $loop <= $pagecount; $loop++) {
    $tplidx = $pdf->importPage($loop);
    $pdf->addPage();
    $pdf->useTemplate($tplidx);
}

$pdf->SetProtection(\FPDI_Protection::FULL_PERMISSIONS);
//$pdf->SetProtection(\FPDI_Protection::FULL_PERMISSIONS, '123456');
//$pdf->SetProtection(\FPDI_Protection::FULL_PERMISSIONS, '123456', 'ABCDEF');

$pdf->Output($dest_file, 'F');

重要

一些 PDF 阅读器(如 Firefox)会忽略保护设置,这大大降低了此脚本的有用性。