'Error - when getting text from pdf file using smalot pdf parser in codeigniter-4
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;
Solution 1:[1]
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>";
}
// ...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | steven7mwesigwa |
