我有一個Web應用程序,用戶可以在其中上傳PDF文檔。有沒有可用於密碼保護PDF文件的PHP庫?我需要庫來保存原始PDF的所有方面(即大小,字體,分辨率等)。如何以PHP密碼保護上傳的PDF
2
A
回答
4
Download the library used: Protect PDF in PHP
<?php
function pdfEncrypt ($origFile, $password, $destFile){
//include the FPDI protection http://www.setasign.de/products/pdf-php-solutions/fpdi-protection-128/
require_once('fpdi/FPDI_Protection.php');
$pdf =& new FPDI_Protection();
// set the format of the destinaton file, in our case 6×9 inch
$pdf->FPDF('P', 'in', array('6','9'));
//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
$password = '[email protected]';
//name of the original file (unprotected)
$origFile = 'book.pdf';
//name of the destination file (password protected and printing rights removed)
$destFile ='book_protected.pdf';
//encrypt the book and create the protected file
pdfEncrypt($origFile, $password, $destFile);
?>
編輯 Original source of library used。請注意,我上面的答案沒有使用源代碼中的腳本進行測試。我從上面的第三方鏈接下載,我沒有檢查它們是否完全一樣。
+1
請指定您從何處下載庫的來源。該頁面將有更多的幫助,直接鏈接到圖書館。 – mccbala
+1
@mccbala看我的編輯。如果您發現此功能有用,請記住+1問題和答案。 –
相關問題
- 1. 如何密碼保護的PDF在PHP
- 2. 如何將受密碼保護的PDF保存爲非密碼保護的PDF
- 3. 密碼保護PDF
- 4. 密碼保護在PHP中的pdf
- 5. iTextSharp - 密碼保護PDF的
- 6. iTextSharp密碼保護PDF
- 7. PHP密碼保護
- 8. PHP密碼保護
- 9. PHP密碼保護
- 10. 保護密碼,javascript傳送給PHP
- 11. 如何在.NET中以編程方式密碼保護pdf?
- 12. 如何在密碼保護頁面上使用WeasyPrint PDF Builder?
- 13. 如何在php中密碼保護zip?
- 14. PDF文件的密碼保護
- 15. 受密碼保護的PDF Jaspersoft
- 16. 密碼保護的PDF不被PdfRenderer
- 17. 密碼保護生成的PDF頁面
- 18. 打開密碼保護的PDF文檔
- 19. php密碼保護網站
- 20. php目錄密碼保護
- 21. php apc.php - 密碼保護
- 22. 以PHP保護上傳的文件
- 23. 使用PLOP密碼保護PDF(PDFLib)
- 24. NReco PDF(精簡版)和密碼保護
- 25. 使用Ghostscript密碼保護PDF
- 26. 用密碼保護pdf文件c#
- 27. iTextsharp用長密碼保護PDF文件
- 28. pdf表格字段密碼保護asp.net
- 29. 使用JavaScript密碼保護pdf
- 30. 打開密碼保護pdf文件
你想密碼保護文件本身,或者只有當你嘗試從你的web應用程序打開它時? –