0

I'm trying to upload a pdf file. It can be password protected or not.

But I receive this error:

Allowed memory size of 134217728 bytes exhausted on line ***print_r($pages);***

This however only happens on PDF files that aren't password protected. Although, the Smalot PDF parser works fine with password protected PDF files.

I already have a helper method removePdfPassword() for removing the password where necessary.

    removePdfPassword($dir . $_FILES["bsfile"]["name"][$i],   $_REQUEST['pdfpassword'][$i], $dir .$file_name);
    include 'public/pdfparser/vendor/autoload.php';
    $parser     = new \Smalot\PdfParser\Parser();
    $location   = $dir . $file_name;
        
    echo "<pre>";
    $pdf        = $parser->parseFile($location);
    $pages      = $pdf->getPages();
    print_r($pages);
    die;
steven7mwesigwa
  • 5,701
  • 3
  • 20
  • 34
  • Does this answer your question? [Using print\_r and var\_dump with circular reference](https://stackoverflow.com/questions/6292164/using-print-r-and-var-dump-with-circular-reference) – steven7mwesigwa Apr 19 '22 at 13:15
  • A bit late to the question but one way to handle this is using `qpdf --decrypt`. – Aaron T May 21 '23 at 09:37

1 Answers1

0

Instead of printing the whole file's pages at once, try doing it in bits. I.e:

Instead of:

// ...

 print_r($pages);

// ....

Use this:

// ...

foreach ($pages as $page) {
    echo "<div>" . $page->getText() . "</div>";
}

// ...
steven7mwesigwa
  • 5,701
  • 3
  • 20
  • 34
  • Thanks @steven7mwesigwa. That line is working for each and every pdf. Anyway that issue has been resolved. Now I'm getting **Secured pdf file are not allowed**. Although pdf is not password protected. – Rohit Dube Apr 22 '22 at 05:06