php pdf创建中的致命错误不';我不知道是什么错误

php pdf创建中的致命错误不';我不知道是什么错误,php,Php,错误是: <?php $pdf=pdf_new(); pdf_open_file($pdf, "test.pdf"); pdf_begin_page($pdf, 595, 842); $arial = pdf_findfont($pdf, "Arial", "host", 1); pdf_setfont($pdf, $arial, 10); pdf_show_xy($pdf, "There are more things in heaven and earth, Horatio,",50

错误是:

<?php
$pdf=pdf_new();
pdf_open_file($pdf, "test.pdf");
pdf_begin_page($pdf, 595, 842);
$arial = pdf_findfont($pdf, "Arial", "host", 1); 
pdf_setfont($pdf, $arial, 10);
pdf_show_xy($pdf, "There are more things in heaven and earth, Horatio,",50, 750);
pdf_end_page($pdf);
pdf_show_xy($pdf, "than are dreamt of in your philosophy", 50,730);
pdf_close($pdf);
?>
致命错误:不能在/var/www/Sample/sam.php:4中的“对象”范围内调用未捕获的异常“PDFlibException”和“message”函数 堆栈跟踪: #0/var/www/Sample/sam.php(4):pdf_begin_页面(资源id#2595842) #第4行的/var/www/Sample/sam.php中抛出了1{main}
问题是pdf_open_file()返回的错误被忽略/未检查

当您尝试执行pdf_begin_page()时,虽然没有有效的打开文件,但PDFlib会引发异常

以下是PDFlib手册中的说明:

PDFlib应用程序必须遵守某些易于理解的结构规则。例如,您显然是在文档结束之前开始文档的。PDFlib通过严格的作用域系统强制执行函数调用的正确顺序。范围定义见PDFlib手册(表1.3)。所有API函数描述都指定了每个函数允许的范围。在允许的范围之外调用函数会导致异常。您可以使用PDF_get_option()的scope keward查询当前作用域

另外,建议使用PDFlib提供的当前示例作为起点,在那里您可以看到当前API与正确的错误处理一起使用

完整的PHP示例如下所示:

Fatal error: Uncaught exception 'PDFlibException' with message 'Function must not be called in 'object' scope' in /var/www/Sample/sam.php:4 Stack trace: #0 /var/www/Sample/sam.php(4): pdf_begin_page(Resource id #2, 595, 842) #1 {main} thrown in /var/www/Sample/sam.php on line 4


这几乎是同一个问题:这能解决您的问题吗?希望这能帮助您@Xavjer还有一个问题没有解决看起来像是未回答的问题请将您的问题更新为新的代码和错误。。。因为第一个错误是因为你使用了贬值的pdf\u begin\u page而不是pdf\u begin\u page\u ext在eclipse中没有类似于pdf\u begin\u page\u ext的函数,我在上面的代码中使用eclipse,它没有显示语法错误,并且你建议的函数不在那里
<?php
/* $Id: hello.php,v 1.20 2013/01/24 16:58:59 rp Exp $
 *
 * PDFlib client: hello example in PHP
 */

try {
    $p = new PDFlib();

    # This means we must check return values of load_font() etc.
    $p->set_option("errorpolicy=return");

    /* all strings are expected as utf8 */
    $p->set_option("stringformat=utf8");

    /*  open new PDF file; insert a file name to create the PDF on disk */
    if ($p->begin_document("", "") == 0) {
        die("Error: " . $p->get_errmsg());
    }

    $p->set_info("Creator", "hello.php");
    $p->set_info("Author", "Rainer Schaaf");
    $p->set_info("Title", "Hello world (PHP)!");

    $p->begin_page_ext(595, 842, "");

    $font = $p->load_font("Helvetica-Bold", "unicode", "");
    if ($font == 0) {
        die("Error: " . $p->get_errmsg());
    }

    $p->setfont($font, 24.0);
    $p->set_text_pos(50, 700);
    $p->show("Hello world!");
    $p->continue_text("(says PHP)");
    $p->end_page_ext("");

    $p->end_document("");

    $buf = $p->get_buffer();
    $len = strlen($buf);

    header("Content-type: application/pdf");
    header("Content-Length: $len");
    header("Content-Disposition: inline; filename=hello.pdf");
    print $buf;

}
catch (PDFlibException $e) {
    die("PDFlib exception occurred in hello sample:\n" .
        "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " .
        $e->get_errmsg() . "\n");
}
catch (Exception $e) {
    die($e);
}

$p = 0;
?>