PDFLib给出了未捕获的异常错误 [英] PDFLib giving an uncaught exception error

查看:311
本文介绍了PDFLib给出了未捕获的异常错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将PDFlib支持加入PHP,但是在最终弄清楚如何安装PDFlib之后,出现此错误:

I'm trying to get PDFlib support into PHP, but after finally figuring out how to install PDFlib, I get this error:

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搜索,但是找不到任何解决方案.

Does anyone have any ideas as to what could be causing this? I've tried googling around, but I've been unable to find any solutions.

推荐答案

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

What version of PDFLib are you using? If it's 6.0 or greater, try this code:

<?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.

这篇关于PDFLib给出了未捕获的异常错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆