【问题标题】:PDFLib giving an uncaught exception errorPDFLib 给出未捕获的异常错误
【发布时间】:2009-06-15 18:37:06
【问题描述】:

我正在尝试将 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);
?>

有没有人知道是什么原因造成的?我试过谷歌搜索,但找不到任何解决方案。

【问题讨论】:

    标签: php pdf pdflib


    【解决方案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 函数都已弃用。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

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

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

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

        【讨论】:

          【解决方案4】:

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

          chmod 0777 -R <PATH>
          

          -R 是递归的

          路径肯定是你存储的

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

          在 $pdf 中。

          【讨论】:

            猜你喜欢
            • 2014-08-26
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2013-07-07
            • 2020-05-30
            相关资源
            最近更新 更多