【问题标题】:Failed to load pdf, dompdf error -> PDF.js v0.8.787 (build: 58407cf) Message: InvalidPDFException加载 pdf 失败,dompdf 错误 -> PDF.js v0.8.787 (build: 58407cf) 消息:InvalidPDFException
【发布时间】:2014-01-27 14:09:39
【问题描述】:

以下是我使用 dompdf 显示 pdf 的代码,但错误是无法加载 pdf PDF.js v0.8.787(内部版本:58407cf) 消息:InvalidPDFException

表名是 acad_act,数据库名是 pbas_db。数据库连接的详细信息存储在 db_connect.php 中。任何帮助都将是可观的

    <?php
            include('db_connect.php');
            require 'dompdf/dompdf_config.inc.php';

    $sqlinv="SELECT * FROM acad_act";
    $res_inv = mysql_query($sqlinv) or die(mysql_error());
    while ($sql3=mysql_fetch_array($res_inv)) {
            $inv_id = $sql3['User_id'];
            $date = $sql3['Year'];
            $cname = $sql3['Gen_Info_AQ'];
            $subtotal = $sql3['Gen_Info_NOC'];
            $disc = $sql3['Gen_Info_Place'];
            $subtotal2 = $sql3['Gen_Info_Duration'];
            $tax = $sql3['Gen_Info_SA'];
            $gtotal = $sql3['Gen_Info_Aqyear'];
    }

    $dompdf= new DOMPDF();

   $html .="<html>
        <head>
        <style>
    body {
        font-family: arial;
        font-size: 13px;
    }
    table {
        width: 100%;
        border-collapse: collapse;
    }
    th {
        font-weight: bold;
        font-size: 14px;
        border: 1px solid #333333;
    }
    tr {
        width: 100%;
    }
    td {
        border: 1px solid #333333;
        text-align: center;
        padding: 10px;
        font-weight: normal!important;
    }
    </style>
    </head><body>";
    $html .="
    <table>
    <thead>
            <tr>
            <th class=''>Sr.</th>
            <th class=''>Particulars</th>
            <th class=''>Size</th>
            <th class=''>Quantity / Insertion</th>
            <th class=''>Rate</th>
            <th class=''>Amount</th>
            <th class=''>Amount 2</th>
            <th class=''>Amount 3</th>
            </tr>
    </thead>
    <tbody>
            <tr>
            <td>" . $inv_id . "</td>
            <td>" . $date . "</td>
            <td>" . $cname . "</td>
            <td>" . $subtotal . "</td>
            <td>" . $disc . "</td>
            <td>" . $subtotal2 . "</td>
            <td>" . $tax . "</td>
            <td>" . $gtotal . "</td>
            </tr>
    </tbody>
    </table>
    </body>
    </html>";

    $dompdf->load_html($html);
    $dompdf->render();

    $dompdf->stream("sample.pdf");

    exit(0);
    ?>

【问题讨论】:

  • 而不是渲染到 dompdf 尝试只是回显 $html 的值以确保没有问题。或者,或者,保存 PDF 并在文本查看器中打开。一些非 PDF 内容可能已在 PDF 输出流中被捕获。
  • 我尝试回显 $html 的内容,但它会导致错误未捕获异常 'DOMPDF_Exception' 并显示消息“需要输入文件(即 input_file _GET 变量)。 DOMPDF_Exception:需要输入文件(即 input_file _GET 变量)。
  • 我也尝试通过简单地使用 php 和 html 在浏览器上显示内容。在这种情况下,数据显示很好,没有任何错误,这意味着上述错误不是由于数据库连接造成的,它必须是由于 localhost 但无法摆脱这个错误..
  • 只有在您使用包含的快速启动脚本 (dompdf.php) 时才会显示该异常。
  • 我只包含了 dompdf_config.inc.php。你的意思是我应该包括 dompdf.php?

标签: php mysql dompdf


【解决方案1】:

异常是由于浏览器中安装了 pdf.js 插件。 pdfjs 不是呈现错误,而是显示一个不显示错误的异常。只需删除 pdfjs 插件即可看到所需的错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-05
    • 1970-01-01
    • 2013-02-08
    • 2011-08-05
    • 2021-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多