DomPDF - addInfo (base64_encode) 和 setEncryption

DomPDF - addInfo (base64_encode) and setEncryption

我对 DomPDF 和 base64_encode setEncryption 函数有问题。

这是我的代码示例。

    // Render the HTML as PDF
    $dompdf->render();

    //Encode title into base64 and add it to PDF Meta
    $title_64 = base64_encode( $title );
    $dompdf->getCanvas()->get_cpdf()->addInfo( 'Subject' , $title_64 );

    //Locking pdf to allow printing only
    $dompdf->getCanvas()->get_cpdf()->setEncryption( '' , '' , array( 'print' ) );

    // Output the generated PDF to Browser
    $dompdf->stream( $post->post_name . ".pdf" , array( "Attachment" => TRUE ) );

下载 PDF 后几乎所有元数据都丢失了。

只要我删除 base64_encode 正在包装的函数 $title 元数据就回来了。

此外,如果我保留 base64_encode 但删除

$dompdf->getCanvas()->get_cpdf()->setEncryption( '' , '' , array( 'print' ) );

一切似乎都正常,但我可以修改我不想要的 PDF。

作为我的最终结果,我应该只能打印我现在拥有的 PDF + 所有元数据

base64_encoded

有没有人遇到过类似的问题?

这是 DomPDF 使用的 CPDF class/version 中的错误。加密字符串未正确转义:

/Producer (Œa6Sq©åðÇ9Å—ÙÒ°Çl¡ÿÝøVóVѪ!Õñ¶7(Þýä¡)

字符串末尾附近有一个左括号,既没有转义也没有平衡。

these lines 中的逻辑有问题。字符串在加密之前被转义,这是完全错误的。