tags:

views:

732

answers:

3

Following are the PHP code lines which I am using to open a PDF file:

$pdf_generartor = new PDFlib();

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

Though the file is at required location, every time I receive following error:

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

Is anyone familiar with the possible solution?

+1  A: 

I think you've just got the file in the wrong place.

Remember, if its linux, its case sensitive.

And if your code is in included files etc, you need to bear that in mind when working out the path if you use it relatively.

Try

echo realpath('Report.pdf');

It will output the path that PHP is translating Report.pdf to, and will likely help you work out why its going wrong.

benlumley
This is not the case and I am using Windows. File is very much in the same directory as the source code file and there is a single code file containing all the code.
VarunGupta
Thats my idea out the window then ..... ! I've not got experience with pdflib, always used FPDF.
benlumley
A: 

Try to give a file from a different path, even mentioning the directory:

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

I know it's a bit overdue, but I ran into this problem myself and managed to "fix" it. Apparently the PDF lib doesn't understand relative paths very well, so you'll have to use realpath().

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

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

or:

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