Is it possible to remove a Password from a PDF file using PHP?
Of course it's possible, all you need to do is reverse engineer the encryption and compression and implement the reverse operations in PHP - but why bother:
<?php
`gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=unencrypted.pdf -c .setpdfwrite -f encrypted.pdf`;
?>
C.
How to password protect pdf in PHP
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 = '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 );
?>
PHP PDF password protection (no open without password)
FPDF (+FPDF_Protection) and also TCPDF will work. You will have to pass BOTH user AND owner password to the setProtection() method. If you leave one as an empty string the viewer application is able to authenticate with this "empty string-password" automatically.
Related Topics
Laravel 5 Carbon Global Locale
How to Keep Leading Zeros in PHP Integer
Soapclient: How to Pass Multiple Elements with Same Name
PHP Domdocument - Get HTML Source of Body
Php: What Is the Purpose of Session_Name
How to Find the Largest Common Substring Between Two Strings in PHP
Sort Array by Date in Descending Order by Date in PHP
How to Set Document Root to Be a Subdirectory Using .Htaccess and Not Vhost
PHP $_Server['Php_Self'] to Include Query String
PHP MySQLi Commands Out of Sync; You Can't Run This Command Now
What Is the Significance of Application Key in a Laravel Application
Session Share Across Multiple Domains on Same Server
Xpath in Simplexml for Default Namespaces Without Needing Prefixes
Facebook Oauthexception: "User Hasn't Authorized the Application to Perform This Action"
Adding User Custom Field Value to Order Items Details
Google Recaptcha - Keep Getting 'Incorrect-Captcha-Sol'