PHP pdf 2 text problem

痴心易碎 提交于 2019-12-11 07:04:10

问题


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


回答1:


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.




回答2:


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




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/5496191/php-pdf-2-text-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!