tcpdfphp
本文給大家介紹的是如何使用php生成pdf文件,並且把該文件加密或設置訪問密碼的方法,有需要的小夥伴可以參考下。
項目需求:php生成pdf文件,並且把該文件加密或設置訪問密碼
開源的TCPDF是基於PHP的一套類庫,它能夠很好的生成PDF格式的文檔。並且支持文件加密,在目前的開源PHP框架、系統、應用中也使用得很廣。這里是設置PDF文檔的相關屬性的方法原型,其中就可以設置密碼
?
1
2
3
4
5
6
7
8
TCPDF::SetProtection
(
$permissions
=
array('print',
'modify',
'',
'annot-forms',
'fill-forms',
'extract',
'assemble',
'print-high'),
$user_pass
=
'',
$owner_pass
=
null,
$mode
=
0,
$pubkeys
=
null
)
通過SetProtection()方法設置後,生成的PDF文檔就是加密過的,在用戶打開PDF文檔的時候就會要求輸入訪問密碼
❷ 如何使用PHP創建和修改PDF文檔
示例一:使用PHP生成一個簡單的PDF文檔
以下為引用的內容:
require_once('../config/lang/eng.php');
require_once('../tcpdf.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 002');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set font
$pdf->SetFont('times', 'BI', 20);