TCPDF:严重性:通知 - >未定义的偏移量:'tcpdf / tcpdf.php'中第20373行的0

时间:2017-07-22 10:19:05

标签: php codeigniter tcpdf

我正在使用TCPDF库在codeigniter中生成PDF。我已经在Codeigniter3中成功集成了TCPDF版本6.2.8库。一切都很好,但有几个通知。我尝试了很多,但无法捕捉到确切的问题。

我的codeigniter模型方法是:

public function saveToPdf($html, $pdfName, $QRCodeData) {
        $this->load->library('Pdf');
        $pdf = new Pdf();
        $pdf->SetAutoPageBreak(TRUE, 10); //set bottom margin
        $pdf->AddPage();
        if ($QRCodeData):
            $pdf->write2DBarcode($QRCodeData, 'QRCODE,H', 180, 13, 75, 75);
        endif;

        $pdf->lastPage();
        $pdf->writeHTML($html);

        return $pdf->Output(APPPATH . "cache" . "/" . $pdfName, 'F');
    }

一切正常,但是这段代码会在很多地方生成未定义偏移的通知。

我的错误日志:

ERROR - 2017-07-22 15:16:12 --> Severity: Notice --> Undefined offset: 0 /var/www/html/ts-2016/api/application/libraries/tcpdf/tcpdf.php 20373
ERROR - 2017-07-22 15:16:12 --> Severity: Notice --> Undefined offset: 0 /var/www/html/ts-2016/api/application/libraries/tcpdf/tcpdf.php 18853
ERROR - 2017-07-22 15:16:12 --> Severity: Notice --> Undefined offset: -1 /var/www/html/ts-2016/api/application/libraries/tcpdf/tcpdf.php 20227
ERROR - 2017-07-22 15:16:12 --> Severity: Notice --> Undefined offset: 0 /var/www/html/ts-2016/api/application/libraries/tcpdf/tcpdf.php 20373
ERROR - 2017-07-22 15:16:12 --> Severity: Notice --> Undefined offset: 0 /var/www/html/ts-2016/api/application/libraries/tcpdf/tcpdf.php 18853
ERROR - 2017-07-22 15:16:12 --> Severity: Notice --> Undefined offset: -1 /var/www/html/ts-2016/api/application/libraries/tcpdf/tcpdf.php 20227
ERROR - 2017-07-22 15:16:12 --> Severity: Notice --> Undefined offset: 0 /var/www/html/ts-2016/api/application/libraries/tcpdf/tcpdf.php 20373
ERROR - 2017-07-22 15:16:12 --> Severity: Notice --> Undefined offset: 0 /var/www/html/ts-2016/api/application/libraries/tcpdf/tcpdf.php 18853
ERROR - 2017-07-22 15:16:12 --> Severity: Notice --> Undefined offset: -1 /var/www/html/ts-2016/api/application/libraries/tcpdf/tcpdf.php 20227
ERROR - 2017-07-22 15:16:12 --> Severity: Notice --> Undefined offset: 0 /var/www/html/ts-2016/api/application/libraries/tcpdf/tcpdf.php 20373

您可以在https://raw.githubusercontent.com/vsjadeja/tcpdf-codeigniter/master/application/libraries/tcpdf/tcpdf.php

上的github.com上查看我的tcpdf.php

请帮帮我。

2 个答案:

答案 0 :(得分:1)

TCPDF仅支持少量HTML标记,如果添加了另一个不受支持的标记,则会出现此严重性错误。

请找到支持的标签列表。

+--------------+-------+----------+-------------+
| <marker>     | <h1>  | <ol>     | <i>         |
+--------------+-------+----------+-------------+
| <a>          | <h2>  | <option> | <img>       |
+--------------+-------+----------+-------------+
| <b>          | <h3>  | <p>      | <input>     |
+--------------+-------+----------+-------------+
| <blockquote> | <h4>  | <pre>    | <label>     |
+--------------+-------+----------+-------------+
| <body>       | <h5>  | <s>      |             |
+--------------+-------+----------+-------------+
| <br>         | <h6>  | <select> | <table>     |
+--------------+-------+----------+-------------+
| <br/>        | <hr>  | <small>  | <thead>     |
+--------------+-------+----------+-------------+
| <dd>         | <hr/> | <span>   | <tablehead> |
+--------------+-------+----------+-------------+
| <del>        |       | <strike> | <th>        |
+--------------+-------+----------+-------------+
| <div>        |       | <strong> | <td>        |
+--------------+-------+----------+-------------+
| <dl>         |       | <sub>    | <tr>        |
+--------------+-------+----------+-------------+
| <dt>         |       | <sup>    |             |
+--------------+-------+----------+-------------+
| <em>         |       |          |             |
+--------------+-------+----------+-------------+
| <font>       |       |          |             |
+--------------+-------+----------+-------------+
| <form>       |       |          |             |
+--------------+-------+----------+-------------+

我希望这会对你有所帮助。

答案 1 :(得分:1)

遇到类似的错误,并通过tcpdf.php进行了跟踪,试图找出问题所在。对我来说似乎tcpdf.php需要链接。它不必使用,只需要使用一个即可。在AddPage()之后添加了一个虚拟对象(至第1页),并且错误消失了!


//添加页面 $ pdf-> AddPage();

$ dummy_tcpdf_undefined_offset_err = $ pdf-> AddLink(); $ pdf-> SetLink($ dummy_tcpdf_undefined_offset_err,0,'* 1');