Question

I'm using Zend_Pdf library for extract text from pdf and I have some problems...

<?php
set_include_path (__DIR__ . '\data'); 
require_once 'Zend/Pdf.php'; 

 // Load PDF document from a file. 
$fileName = 'carbsarticle.pdf'; 
$pdf = new Zend_Pdf($fileName); 
$pdf = Zend_Pdf::parse($pdf); 
var_dump($pdf);

Fatal error: Uncaught exception 'Zend_Pdf_Exception' with message 'File is not a PDF.'

I tried to download other pdf file, but the error is the same ..

EDIT:

try {
    $pdf2 = Zend_Pdf::load('test.pdf');
} catch (Exception $e)
{
    echo $e->getMessage();
}

This echoes: Encrypted document modification is not supported

My pdf: http://x3k.ru/test.pdf

Was it helpful?

Solution

Okay just saw the usage at zend documentation

#
// Load a PDF document from a file
#
$pdf2 = Zend_Pdf::load($fileName);
#

#
// Load a PDF document from a string
#
$pdf3 = Zend_Pdf::parse($pdfString);
#
...

This is how you load a PDF file.

OTHER TIPS

Check your directory path. May be you need to set as set_include_path (__DIR__ . '\data\');

The PDF file is copy-protected, i guess :) Use other file - say download something from internet.

I had an issue like this a while back with a pdf I received from someone. I had to remove the password protection altogether in order for Zend to work with it at all. Zend will not modify any encrypted docs. I ended up getting a PDF decrypter to do the job, there's plenty out there if you've lost the original password.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top