【问题标题】:mPDF v8.0.4 - setProtection function it is not working as expectedmPDF v8.0.4 - setProtection 功能未按预期工作
【发布时间】:2021-12-07 12:48:20
【问题描述】:

我正在尝试使用函数 setProtection() 的功能。

  1. 我感觉生成的文件没有受到保护,因为我可以复制和打印文件内容。

根据文档,复制、打印等所有操作都应拒绝下载后试图操作文件的人。 Example #1

// Encrypt the file and grant no permissions to the user to copy, print etc.
// The user will be able to open the file as no password is specified
// Owner cannot access full rights because no owner_password was set

$mpdf->SetProtection(array());
  1. 我是否在文件中的正确位置使用了该函数?

  2. 这个方法有什么bug需要修复吗?

  3. 是否有其他解决方案可以用来保护将要生成的文件? API 还是其他东西?

  4. 作为 PDF 阅读器工具,我是 Evince V.2.32.0.145

这是代码:非常感谢。

// Security method
$mpdf->SetProtection(array());

//$mpdf->SetProtection(array('print-highres'), '', 'test123456&&987%654', 128);

$mpdf->SetTitle("Quorum sine causa fieri nihil");
$mpdf->SetAuthor('Quorum sine causa fieri nihil');
$mpdf->SetCreator('Quorum sine causa fieri nihil');
$mpdf->SetSubject('Quorum sine causa fieri nihil');
$mpdf->SetKeywords('Quorum sine causa fieri nihil');

$css = file_get_contents(__DIR__. '/assets/css/mpdf.css');

$mpdf->WriteHTML($css,1,\Mpdf\HTMLParserMode::HEADER_CSS); // Load the CSS

$mpdf->WriteHTML($html,\Mpdf\HTMLParserMode::HTML_BODY);// Load the html

// INVOICE name generated.
$fileName = 'Invoicename'.'_'.date('D-d-m-Y-H-i-s').'_'.$order_id.'.pdf';

$mpdf->Output($fileName,"D");

$mpdf->cleanup();

【问题讨论】:

    标签: php pdf-generation mpdf


    【解决方案1】:

    看来您需要使用SetProtection 函数设置权限、用户和密码。

    // Encrypt the file and grant no permissions to the user
    // The user will need to use "UserPassword" to open the file
    // Owner has full rights using the password "MyPassword"
    $mpdf->SetProtection(array(), 'UserPassword', 'MyPassword');
    

    这里的文档:

    https://mpdf.github.io/reference/mpdf-functions/setprotection.html

    【讨论】:

    • 你能在代码注释行看到这条注释吗? // 加密文件并且不授予用户权限。使用这行代码没有任何意义!
    • @PaulodoPorto 这将阻止用户复制和打印文档。不确定您是否给我-1,如果是,您的解决方案是什么?
    • 你好@Bossman。经过8个多小时试图找到我可以说的解决方案。关键是,setProtection 方法不适用于我上面直接描述的问题。
    • 1° 用密码阻止任何用户的文件是没有意义的。 2° 同样,使用密码赋予所有者作为我的全部权利也没有任何意义。我发现您并没有真正阅读这个问题,而是在尝试另一件没有意义的事情。
    • 很抱歉试图提供帮助。我看不到 PDF 在没有凭据的情况下受到保护,我可能是错的(很有可能)。我现在唯一可以建议的是直接在 github 上提交问题:github.com/mpdf/mpdf。同样,只是想提供帮助。
    猜你喜欢
    • 2013-08-29
    • 2020-04-28
    • 2021-08-27
    • 1970-01-01
    • 2012-10-07
    • 2014-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多