打开时加密dompdf

时间:2016-03-19 06:03:15

标签: php encryption dompdf

我正在加密我的pdf但是当我打开它并输入密码时,它总是说错误的错误这是我的代码:

    global $_dompdf_show_warnings;
    global $_dompdf_debug;
    global $_DOMPDF_DEBUG_TYPES;

    $outfile = $id . '_qr_codes.pdf';
    $save_file = TRUE; // Save the file or not

    $buff = $this->qr_generate_pdf($id);
    //echo $buff; die;
    $dompdf = new DOMPDF();

    $dompdf->load_html($buff);
    if (isset($base_path)) {
        $dompdf->set_base_path($base_path);
    }
    $dompdf->render(); 
        $dompdf->get_canvas()->get_cpdf()->setEncryption('admin','ownerpass');

    if ($_dompdf_show_warnings) {
        global $_dompdf_warnings;
        foreach ($_dompdf_warnings as $msg) {
            echo $msg . "\n";
        }
        echo $dompdf->get_canvas()->get_cpdf()->messages;
        flush();
    }
      if ($save_file) {
        // if ( !is_writable($outfile) )
        // throw new DOMPDF_Exception("'$outfile' is not writable.");

        if (strtolower(DOMPDF_PDF_BACKEND) == "gd") {
            $outfile = str_replace(".pdf", ".png", $outfile);
        }

        list($proto, $host, $path, $file) = explode_url($outfile);

        if ($proto != "") // i.e. not file://
            $outfile = $file; // just save it locally, FIXME? could save it like wget: ./host/basepath/file
        //$outfile = dompdf_realpath($outfile);
        // if ( strpos($outfile, DOMPDF_CHROOT) !== 0 )
        // throw new DOMPDF_Exception("Permission denied.");
        file_put_contents($outfile, $dompdf->output(array("compress" => 0)));
    }

    if (!headers_sent())
        $dompdf->stream($outfile);
}

当我在下载的pdf中输入密码'ownerpass'时,它会出现错误 - >密码不正确。请确保错误地打开了大写锁定,然后重试。 提前致谢

0 个答案:

没有答案