wordpress DomPDF - addInfo(base64_encode)和setEncryption

8e2ybdfx  于 9个月前  发布在  WordPress
关注(0)|答案(1)|浏览(97)

我在使用DomPDF和带有setEncryption函数的base64_encode时遇到了问题。
这是我的代码的一个示例。

// 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下载所有的Meta数据丢失。
只要我删除base64_encode函数,即 Package $title Meta数据回来。
另外,如果我保留base64_encode但删除
$dompdf->getCanvas()->get_cpdf()->setEncryption( '' , '' , array( 'print' ) );
一切似乎都在工作,但我能够修改我不想要的PDF。
作为我的最终结果,我应该只能打印PDF,这是我现在所拥有的+所有Meta数据将是
base64_encoded
是否有人遇到过类似问题?

lnlaulya

lnlaulya1#

这是DomPDF使用的CPDF类/版本中的一个错误。加密的字符串没有正确转义:

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

字符串
在字符串的末尾有一个开括号,它既不转义也不平衡。
这几行的逻辑是错误的。字符串在加密之前被转义了,这是完全错误的。

相关问题