FIX better method to check if pdf is protected/encrypted
This commit is contained in:
parent
5530e003ba
commit
43ada3fcd4
@ -175,18 +175,29 @@ function pdf_getInstance($format = '', $metric = 'mm', $pagetype = 'P')
|
||||
/**
|
||||
* Return if pdf file is protected/encrypted
|
||||
*
|
||||
* @param TCPDF $pdf PDF initialized object
|
||||
* @param string $pathoffile Path of file
|
||||
* @return boolean True or false
|
||||
*/
|
||||
function pdf_getEncryption(&$pdf, $pathoffile)
|
||||
function pdf_getEncryption($pathoffile)
|
||||
{
|
||||
require_once TCPDF_PATH.'tcpdf_parser.php';
|
||||
|
||||
$isencrypted = false;
|
||||
|
||||
$pdfparser = $pdf->_getPdfParser($pathoffile);
|
||||
$data = $pdfparser->getParsedData();
|
||||
if (isset($data[0]['trailer'][1]['/Encrypt'])) {
|
||||
$isencrypted = true;
|
||||
$content = file_get_contents($pathoffile);
|
||||
|
||||
ob_start();
|
||||
@($parser = new \TCPDF_PARSER(ltrim($content)));
|
||||
list($xref, $data) = $parser->getParsedData();
|
||||
unset($parser);
|
||||
ob_end_clean();
|
||||
|
||||
if (isset($xref['trailer']['encrypt'])) {
|
||||
$isencrypted = true; // Secured pdf file are currently not supported
|
||||
}
|
||||
|
||||
if (empty($data)) {
|
||||
$isencrypted = true; // Object list not found. Possible secured file
|
||||
}
|
||||
|
||||
return $isencrypted;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user