PDFLib: Cannot open PDF file

Below are the lines of PHP code I am using to open the PDF file:

$pdf_generartor = new PDFlib();

$doc = $pdf_generartor -> open_pdi_document("Report.pdf", "") or die ("ERROR: " . $pdf_generartor -> get_errmsg());

      

Although the file is in the right place, every time I get the following error:

ERROR: Couldn't open PDF file 'Report.pdf' for reading (file not found)

      

Anyone familiar with a possible solution?

+1


source to share


3 answers


I know this is a little late, but I ran into this problem and managed to "fix" it. Apparently the PDF library doesn't understand relative paths very well, so you'll have to use realpath ().

When you look at the samples, you can do this in two ways. You can use realpath () with actual file paths, or use realpath () with a "lookup directory".

$p = new PDFlib();
$p->set_parameter("SearchPath", realpath("data/"));

      



or

$indoc = $p->open_pdi_document(realpath($infile), "");

      

+2


source


I think you have a file in the wrong place.

Remember, if its linux, its case is case sensitive.

And if your code is included in files with files, etc., you should take this into account when designing the path if you use it relatively.



Try

echo realpath('Report.pdf');

      

It will print the path PHP is translating the Report.pdf into and will most likely help you figure out why it is wrong.

+1


source


Try giving the file from a different path, even specifying a directory:

 $doc = $pdf_generartor->open_pdi_document("D:\\Report.pdf", "") or die ("ERROR:")

      

0


source







All Articles