Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

PDF2Text not working with some pdfs WordPress

  • SOLVED

Pretty straightforward here, trying to read pdfs with PDF2Text, but it isn't working with certain pdfs... here is the test code:

add_shortcode('testpdf','testpdff');
function testpdff(){

$a = new PDF2Text();
$a->setFilename( '/var/www/site.com/wp-content/uploads/gravity_forms/1-3d2723fb5e69ca7174ef377127f85351/tmp/shoppinglist.pdf' );
$a->decodePDF();
//print_r( $a );
$out = $a->output();
echo $out;
echo '<br>finished.';

}


Here is a copy of the pdf2text class: [[LINK href="https://github.com/asika32764/php-pdf-2-text/blob/master/src/Pdf2text.php"]]https://github.com/asika32764/php-pdf-2-text/blob/master/src/Pdf2text.php[[/LINK]]


Now if I change the filename to pdf-sample.pdf (same directory and path, it is a different and simpler pdf file), it works. The files are public so you can look at them. If you have experience with this and know why it may not be reading it, let me know.

Answers (2)

2016-04-04

Rempty answers:

The problem is:
The pdf is using DCTDecode filter and the class are you using don't support DCTDecode

I made some tests with this class and it worked
https://gist.github.com/smalot/6183152

$pparser=new PdfParser;
echo $pparser->parseFile('http://charlestonxpress.blueskycoding.com/wp-content/uploads/gravity_forms/1-3d2723fb5e69ca7174ef377127f85351/tmp/shoppinglist.pdf');


Kyle comments:

Thanks!

And extra thanks for taking the time to not just post the found issue, but taking the time to also come up with a solution, I will up the prize.

2016-04-04

Shoeb mirza answers:

add_shortcode('testpdf','testpdff');
function testpdff(){
$a = new PDF2Text();
$a->setFilename( 'shoppinglist.pdf' );
$a->decodePDF();
//print_r( $a );
$out = $a->output();
echo $out;
echo '<br>finished.';
}

Post pdf in the root


Kyle comments:

Thanks for the reply. Unfortunately, it didn't change the result.