PDFLib:无法打开 PDF 文件
以下是我用来打开 PDF 文件的 PHP 代码行:
$pdf_generartor = new PDFlib();
$doc = $pdf_generartor -> open_pdi_document("Report.pdf", "") or die ("ERROR: " . $pdf_generartor -> get_errmsg());
虽然文件位于所需位置,但每次我收到以下错误:
ERROR: Couldn't open PDF file 'Report.pdf' for reading (file not found)
有人熟悉可能的解决方案吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这有点迟了,但我自己也遇到了这个问题并设法“修复”它。 显然 PDF 库不能很好地理解相对路径,因此您必须使用 realpath()。
当您查看示例时,您可以通过两种方式执行此操作。 您可以将 realpath() 与实际文件路径一起使用,或将 realpath() 与“搜索目录”一起使用。
或者:
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".
or:
我认为您刚刚将该文件放在了错误的位置。
请记住,如果是 Linux,则区分大小写。
如果您的代码位于包含文件等中,则在相对使用路径时需要记住这一点。
Try
It 将输出 PHP 将 Report.pdf 翻译到的路径,并且可能会帮助您找出出错的原因。
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
It will output the path that PHP is translating Report.pdf to, and will likely help you work out why its going wrong.
尝试从不同的路径提供文件,甚至提及目录:
Try to give a file from a different path, even mentioning the directory: