简体   繁体   中英

PDFLib: Can't open a PDF file

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?

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), "");

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.

尝试从其他路径提供文件,甚至提到目录:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM