公告:本站整合全网多家VIP站点资源,全网虚拟资源一手掌握!!!
欢迎您访问本网站,请 注 册了解更多!
网站首页 > 网站源码 > IT技术 > php > 正文

如何创建受密码保护的pdf文件

作者:免费资源网日期:2022-10-16浏览:317分类:php

<?php
    function pdfEncrypt ($origFile, $password, $destFile){        require_once('FPDI_Protection.php');
        $pdf =& new FPDI_Protection();
        $pdf->FPDF('P', 'in');        //Calculate the number of pages from the original document.
        $pagecount = $pdf->setSourceFile($origFile);        //Copy all pages from the old unprotected pdf in the new one.
        for ($loop = 1; $loop <= $pagecount; $loop++) {
            $tplidx = $pdf->importPage($loop);
            $pdf->addPage();
            $pdf->useTemplate($tplidx);
        }        //Protect the new pdf file, and allow no printing, copy, etc. and
        //leave only reading allowed.
        $pdf->SetProtection(array(), $password);
        $pdf->Output($destFile, 'F');        return $destFile;
    }    //Password for the PDF file (I suggest using the email adress of the purchaser).
    $password = "testpassword";    //Name of the original file (unprotected).
    $origFile = "sample.pdf";    //Name of the destination file (password protected and printing rights removed).
    $destFile ="sample_protected.pdf";    //Encrypt the book and create the protected file.
    pdfEncrypt($origFile, $password, $destFile );?>

本站所有资源都来源于网络收集、网友提供或者交换而来!如果侵犯了您的权益,请及时联系本站客服,我们立刻删除!

暂无评论,来添加一个吧。

取消回复欢迎 发表评论:

你的会员级别无法评论,请升级会员