我需要使用php中的mpdf为已经生成的pdf文件设置密码。
答案 0 :(得分:0)
抱歉英语最差。
下面是我的代码:
//将pdf转换为jpg $ imagick = new imagick();
$imagick->readImage(base_url().'pdffiles/'.$faxid.'.pdf');
foreach($imagick as $i => $imagick) {
$imagick->setImageFormat('jpeg');
$imagick->setResolution(300,300);
header('Content-Type: image/jpeg');
$path1 = './pdffiles/'.$faxid.'_'.$i.'.jpg';
file_put_contents($path1, $imagick );
}
// Convert jpg to pdf with password protection
$this->load->library('Tc_pdf');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetProtection(array('print', 'copy','modify'), $loggedInUser, "ourcodeworld-master", 0, null);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetFont('courier', '', 20);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//$dir = base_url()."/pdffiles/";
$map = directory_map('./pdffiles/');
foreach ($map as $key => $value) {
$extention = explode('.', $value);
if($extention[1] == 'jpg') {
$pdf->AddPage();
$img = file_get_contents('./pdffiles/'.$value);
$pdf->Image('@' . $img, 20, 20, '', '', 'JPG', '', 'T', false, 100, '', false, false, 0, false, false, false);
}
}
foreach ($map as $key => $value) {
@unlink('./pdffiles/'.$value);
}
$pdf->Output('example.pdf', 'I');