blank
  ID Security Suite HomeHomeProductsProductsDownloadDownloadPurchaseBuy nowSupport
Security Tools blank Optimization & Cleanup Tools blank Maintenance Tools blank Protection Tools
 
 
 
 
News Archive Index
bulletThe ID Security Suite News Archive is being updated on regular basis, so please check in from time to time for up to date articles on PC Security issues.
 
arrow Time [GMT - 2] : 18 Dec , 14:05:41  bulletNews Archive Index    blank blank bulletSecurity categories:
  bullet Password protect a PDF document in PHP

Posted in : Maintenance  |  Posted by : Cristina Mailat
October 7th, 2008 |

download the library used: Protect PDF in PHP

Check bellow the solution I found for on the fly protecting a PDF file in PHP. For resolving this problem I wanted a FREE librar. Download from above the libraries and use the code bellow for password protect a PDF file using 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 (I suggest using the email adress of the purchaser)
$password = “info@domain.com”;

//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 );
?>


Leave a Reply

 

 
bullet Maintenance
bullet Optimization and Cleanup
bullet Protection
bullet Security
bullet Press room
bullet News

bulletSecurity resources:
bullet C|net Security
bullet ZDNet Security
bullet InternetNews Security
bullet PC Mag Security

bulletContent RSS feeds:
bullet News feed
bullet Comments feed
ID Community Forums  |  News Archive  |  Newsletters  |  FAQ  |  Affiliates  |  Sitemap
Terms & Conditions  |  Privacy Policy  | FASTLINK 2. All Rights Reserved.
blank