0

我正在尝试将 PDFlib 支持添加到 PHP 中,但在最终弄清楚如何安装 PDFlib 之后,我收到了这个错误:

Fatal error: Uncaught exception 'PDFlibException' with message 'Function must not be called in 'object' scope'

使用php.net上的示例代码:

<?php
// create handle for new PDF document
$pdf = pdf_new();
// open a file
pdf_open_file($pdf, "test.pdf");
// start a new page (A4)
pdf_begin_page($pdf, 595, 842);
// get and use a font object
$arial = pdf_findfont($pdf, "Arial", "host", 1); pdf_setfont($pdf, $arial, 10);
// print text
pdf_show_xy($pdf, "There are more things in heaven and earth, Horatio,",50, 750);
pdf_show_xy($pdf, "than are dreamt of in your philosophy", 50,730);
// end page
pdf_end_page($pdf);
// close and save file
pdf_close($pdf);
?>

有没有人对可能导致这种情况的原因有任何想法?我试过用谷歌搜索,但我找不到任何解决方案。

4

4 回答 4

1

您使用的是什么版本的 PDFLib?如果是 6.0 或更高版本,请尝试以下代码:

<?php
// create handle for new PDF document
$pdf = PDF_new();
// open a file
PDF_begin_document($pdf, "test.pdf");
// start a new page (A4)
PDF_begin_page_ext($pdf, 595, 842);
// get and use a font object
$arial = PDF_load_font($pdf, "Arial", "host", 1); pdf_setfont($pdf, $arial, 10);
// print text
PDF_show_xy($pdf, "There are more things in heaven and earth, Horatio,",50, 750);
PDF_show_xy($pdf, "than are dreamt of in your philosophy", 50,730);
// end page
PDF_end_page_exit($pdf);
// close and save file
PDF_end_document($pdf);
?>

这些功能pdf_open_file, pdf_begin_page, pdf_findfont, and pdf_close都已弃用。

于 2009-06-15T18:59:56.727 回答
0

请检查您创建文件的路径。

pdf_open_file($pdf, "test.pdf");

只要确保路径正确,错误就会消失。

于 2011-05-10T12:30:05.823 回答
0

检查您要经过的位置的许可。我的也是固定的。它应该有写权限。

chmod 0777 -R <PATH>

-R 是递归的

路径肯定是你存储在

pdf_open_file($pdf, "test.pdf");

在 $pdf 中。

于 2015-03-20T11:19:34.637 回答
0

或者以“硬”且非常不好的方式 - 尝试将您的代码移动到全局范围内。

于 2011-03-12T10:06:30.713 回答