當前位置:首頁 » 編程語言 » tcpdfphp

tcpdfphp

發布時間: 2023-09-05 08:05:44

php生成PDF格式文件並且加密

本文給大家介紹的是如何使用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);

熱點內容
linux命令清理 發布:2025-03-12 23:17:15 瀏覽:5
手機文件夾趣味名字6個 發布:2025-03-12 23:17:12 瀏覽:497
解釋程序和編譯程序 發布:2025-03-12 23:15:47 瀏覽:571
色豬視頻為什麼沒有伺服器 發布:2025-03-12 23:15:46 瀏覽:123
如龍極2低配置怎麼調 發布:2025-03-12 23:14:06 瀏覽:374
androidopencamera 發布:2025-03-12 23:05:27 瀏覽:816
雲購網源碼 發布:2025-03-12 23:00:29 瀏覽:618
騰訊雲伺服器上的電腦打不開 發布:2025-03-12 22:55:29 瀏覽:942
安卓系統怎麼退出遊戲 發布:2025-03-12 22:42:37 瀏覽:665
高強度加密大師忘記密碼 發布:2025-03-12 22:37:11 瀏覽:177