I am trying to use the library PDFparser using the composer.
I know it is installed in /home/servername/vendor/smalot/pdfparser
My php script is found in /home/servername/public_html/test.php
This is my code:
<?php
ini_set('display_errors',true);
include 'vendor/autoload.php';
$parser = new \Smalot\PdfParser\Parser();
?>
and this is the error I am getting:
Warning: include(vendor/autoload.php): failed to open stream: No such file or directory in /home/servername/public_html/test.php on line 3
Warning: include(): Failed opening 'vendor/autoload.php' for inclusion (include_path='.:/usr/share/php') in /home/servername/public_html/test.php on line 3
Fatal error: Uncaught Error: Class 'Smalot\PdfParser\Parser' not found in /home/servername/public_html/test.php:4 Stack trace: #0 {main} thrown in /home/servername/public_html/test.php on line 4
What am I doing wrong? This is my first time using a php library
My Answer:
php
require '/home/servername/vendor/autoload.php';
use Smalot\PdfParser\Parser;
$parser = new Parser();
$pdf = $parser->parseFile('/path/to/your/pdf/file.pdf');
$text = $pdf->getText();
echo $text;
Make sure to replace `/path/to/your/pdf/file.pdf` with the actual path to your PDF file. This code will parse the PDF file and output the text content.
Rate this post
3 of 5 based on 7680 votesComments