I need to extract heading of my PDF file which are starting with # symbols through php or javascript. I don’t know how to do it. here is my PDF file link.
https://afxwebdesign.com/order.pdf
I have tried this scrip.
<code><?php
// Load the PDF file
$pdfFile = 'order.pdf';
// Use a PDF parsing library like TCPDF or FPDI to extract text
// Code snippet using TCPDF
require_once('tcpdf.php');
require_once('vendor/setasign/fpdi/src/autoload.php');
use setasignFpdiTcpdfFpdi;
$pdf = new Fpdi();
$pageCount = $pdf->setSourceFile($pdfFile);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
$templateId = $pdf->importPage($pageNo);
$text = $pdf->getPageContent($pageNo);
preg_match_all('/^#[^#].*$/m', $text, $headings);
foreach ($headings[0] as $heading) {
echo $heading . "n";
}
}
$pdf->close();
?>
</code>
<code><?php
// Load the PDF file
$pdfFile = 'order.pdf';
// Use a PDF parsing library like TCPDF or FPDI to extract text
// Code snippet using TCPDF
require_once('tcpdf.php');
require_once('vendor/setasign/fpdi/src/autoload.php');
use setasignFpdiTcpdfFpdi;
$pdf = new Fpdi();
$pageCount = $pdf->setSourceFile($pdfFile);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
$templateId = $pdf->importPage($pageNo);
$text = $pdf->getPageContent($pageNo);
preg_match_all('/^#[^#].*$/m', $text, $headings);
foreach ($headings[0] as $heading) {
echo $heading . "n";
}
}
$pdf->close();
?>
</code>
<?php
// Load the PDF file
$pdfFile = 'order.pdf';
// Use a PDF parsing library like TCPDF or FPDI to extract text
// Code snippet using TCPDF
require_once('tcpdf.php');
require_once('vendor/setasign/fpdi/src/autoload.php');
use setasignFpdiTcpdfFpdi;
$pdf = new Fpdi();
$pageCount = $pdf->setSourceFile($pdfFile);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
$templateId = $pdf->importPage($pageNo);
$text = $pdf->getPageContent($pageNo);
preg_match_all('/^#[^#].*$/m', $text, $headings);
foreach ($headings[0] as $heading) {
echo $heading . "n";
}
}
$pdf->close();
?>
But its not working it has this error
<code>Fatal error: Uncaught Error: Call to undefined method setasignFpdiTcpdfFpdi::getPageContent() in C:xampphtdocspdfextractindex.php:17 Stack trace: #0 {main} thrown in C:xampphtdocspdfextractindex.php on line 17
</code>
<code>Fatal error: Uncaught Error: Call to undefined method setasignFpdiTcpdfFpdi::getPageContent() in C:xampphtdocspdfextractindex.php:17 Stack trace: #0 {main} thrown in C:xampphtdocspdfextractindex.php on line 17
</code>
Fatal error: Uncaught Error: Call to undefined method setasignFpdiTcpdfFpdi::getPageContent() in C:xampphtdocspdfextractindex.php:17 Stack trace: #0 {main} thrown in C:xampphtdocspdfextractindex.php on line 17
New contributor
Kamran Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.