2009-06-15 41 views
0

我试图获得支持的PDFlib到PHP,但后,终于搞清楚如何安装PDFlib,所以我得到这个错误: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); 
?> 

有没有人有什么想法,可能是什么原因造成的?我尝试过使用Google搜索,但我一直无法找到任何解决方案。

回答

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都已过时。

0

或者用“硬”而非常不好的方法 - 尝试将代码移到全局范围的某处。

0

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

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

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

0

检查您所在位置的许可。我的做法是一样的。它应该有写入权限。

chmod 0777 -R <PATH> 

-R是递归

路径肯定是你存储在

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

在$ PDF格式。

相关问题