TCPDF在生成要打印的表结构时返回错误

时间:2014-10-02 11:21:29

标签: php tcpdf

我正在使用TCPDF在SmartJobBoard中工作。 PDF是在旧服务器上正确生成的。

我们将网站移至新服务器后,在创建PDF发票时开始显示错误。 TCPDF库显示以下错误。

Notice: Undefined index: cols in /home/pb_admin/public_html/pb/system/ext/tcpdf/tcpdf.php on line 22174
Notice: Undefined index: thead in /home/pb_admin/public_html/pb/system/ext/tcpdf/tcpdf.php on line 21705
Notice: Undefined index: rows in /home/pb_admin/public_html/pb/system/ext/tcpdf/tcpdf.php on line 22162
Warning: array_push() expects parameter 1 to be array, null given in /home/pb_admin/public_html/pb/system/ext/tcpdf/tcpdf.php on line 22164
Warning: array_push() expects parameter 1 to be array, null given in /home/pb_admin/public_html/pb/system/ext/tcpdf/tcpdf.php on line 22164
Warning: array_push() expects parameter 1 to be array, null given in /home/pb_admin/public_html/pb/system/ext/tcpdf/tcpdf.php on line 22164
Notice: Undefined index: thead in /home/pb_admin/public_html/pb/system/ext/tcpdf/tcpdf.php on line 21718

Exception Object
(
    [message:protected] => PDF generation failed: Some data has already been output, can't send PDF file
    [string:Exception:private] => 
    [code:protected] => 0
    [file:protected] => /home/pb_admin/public_html/pb/system/ext/tcpdf/tcpdf.php
    [line:protected] => 29841
    [trace:Exception:private] => Array
        (
            [0] => Array
                (
                    [file] => /home/pb_admin/public_html/pb/system/ext/tcpdf/tcpdf.php
                    [line] => 9062
                    [function] => Error
                    [class] => ExceptionThrowingTCPDF
                    [type] => ->
                    [args] => Array
                        (
                            [0] => Some data has already been output, can't send PDF file
                        )

                )

            [1] => Array
                (
                    [file] => /home/pb_admin/public_html/pb/system/lib/payment/Invoices/InvoiceManager.php
                    [line] => 141
                    [function] => Output
                    [class] => TCPDF
                    [type] => ->
                    [args] => Array
                        (
                            [0] => invoice_3284.pdf
                            [1] => D
                        )

                )

            [2] => Array
                (
                    [file] => /home/pb_admin/public_html/pb/system/user-scripts/payment/view_invoice.php
                    [line] => 55
                    [function] => generatePDFVersion
                    [class] => SJB_InvoiceManager
                    [type] => ::
                    [args] => Array
                        (
                            [0] => 




Rechnung

Datum: 01.10.2014
Rechnung #3284
Status der Rechnung: In Bearbeitung (Zahlung auf Rechnung (Abonnement wird freigeschalten, sobald Zahlungseingang erfolgt ist.))

Rechnungsempfänger





Zahlungsempfänger

Ocean Harvest GmbH
Ruessenstrasse 18
6340 Baar

Konto:
Bank: UBS AG, Zug
IBAN: CH81 0027 3273 1186 8701 T


Beschreibung    Betrag
PlacementBooster.ch
Firmen-Abonnement: 12 Monate
50 Mitarbeiter (51 Accounts)    CHF 13,808.00
Zwischensumme   CHF 13,808.00
MWST-Nr. CHE-108.643.082 MWST MWST Ref.-Nr. 417985  CHF 1,104.64
Insgesamt   CHF 14,912.64

                            [1] => 3284
                        )

                )

            [3] => Array
                (
                    [file] => /home/pb_admin/public_html/pb/system/core/ModuleManager.php
                    [line] => 127
                    [function] => execute
                    [class] => SJB_Payment_ViewInvoice
                    [type] => ->
                    [args] => Array
                        (
                        )

                )

            [4] => Array
                (
                    [file] => /home/pb_admin/public_html/pb/system/core/System.php
                    [line] => 140
                    [function] => executeFunction
                    [class] => SJB_ModuleManager
                    [type] => ->
                    [args] => Array
                        (
                            [0] => payment
                            [1] => view_invoice
                            [2] => 
                            [3] => /view-invoice/
                        )

                )

            [5] => Array
                (
                    [file] => /home/pb_admin/public_html/pb/system/core/PageConstructor.php
                    [line] => 29
                    [function] => executeFunction
                    [class] => SJB_System
                    [type] => ::
                    [args] => Array
                        (
                            [0] => payment
                            [1] => view_invoice
                            [2] => 
                            [3] => /view-invoice/
                        )

                )

            [6] => Array
                (
                    [file] => /home/pb_admin/public_html/pb/system/core/System.php
                    [line] => 193
                    [function] => getPage
                    [class] => SJB_PageConstructor
                    [type] => ::
                    [args] => Array
                        (
                            [0] => SJB_UserPageConfig Object
                                (
                                    [uri] => /view-invoice/
                                    [module] => payment
                                    [function] => view_invoice
                                    [template] => 
                                    [title] => View Invoice
                                    [parameters] => 
                                    [keywords] => 
                                    [page_exists] => 1
                                    [page_id] => 539
                                    [has_raw_output] => 
                                    [numberOfViews] => 
                                    [description] => 
                                )

                        )

                )

            [7] => Array
                (
                    [file] => /home/pb_admin/public_html/pb/system/core/Request.php
                    [line] => 209
                    [function] => getPage
                    [class] => SJB_System
                    [type] => ::
                    [args] => Array
                        (
                            [0] => SJB_UserPageConfig Object
                                (
                                    [uri] => /view-invoice/
                                    [module] => payment
                                    [function] => view_invoice
                                    [template] => 
                                    [title] => View Invoice
                                    [parameters] => 
                                    [keywords] => 
                                    [page_exists] => 1
                                    [page_id] => 539
                                    [has_raw_output] => 
                                    [numberOfViews] => 
                                    [description] => 
                                )

                        )

                )

            [8] => Array
                (
                    [file] => /home/pb_admin/public_html/pb/index.php
                    [line] => 72
                    [function] => execute
                    [class] => SJB_Request
                    [type] => ->
                    [args] => Array
                        (
                        )

                )

        )

    [previous:Exception:private] => 
)

为什么会发生这种错误?

8 个答案:

答案 0 :(得分:4)

尝试插入...

//Change To Avoid the PDF Error
  ob_end_clean();

如果这不起作用,请尝试使用ob_clean();代替。

就在你做之前:

$pdf->Output($filename, $output_dest);

发生错误是因为TCPDF在最终呈现完成之前抛出错误。为了防止TCPDF创建不起作用的PDF,它决定崩溃。

万一TCPDF不再喜欢你了,看看DomPDF:)

答案 1 :(得分:4)

TCPDF需要100%有效的XHTML语法

即使“HTML Tidy”也不会向您显示所有html错误。在我的情况下,我有一个tr标签没有关闭,并在我纠正这个警告消失后,但pdf文件很难看。例如,通过colspan=12更改colspan=”12”rowspan=2更改rowspan=”2”来解决问题。

答案 2 :(得分:1)

问题是您的PHP脚本在发送PDF之前打印到浏览器。为什么在发送PDF之前PHP打印到浏览器?因为存在错误,PHP配置为向浏览器打印错误。

上面给出的两个解决方案是压制错误的(不好)解决方法。修复代码,错误将消失,然后可以正确发送PDF。

为什么PHP会抛出错误?我们来看看:

Notice: Undefined index: cols in /home/pb_admin/public_html/pb/system/ext/tcpdf/tcpdf.php on line 22174
Notice: Undefined index: thead in /home/pb_admin/public_html/pb/system/ext/tcpdf/tcpdf.php on line 21705
Notice: Undefined index: rows in /home/pb_admin/public_html/pb/system/ext/tcpdf/tcpdf.php on line 22162
Warning: array_push() expects parameter 1 to be array, null given in /home/pb_admin/public_html/pb/system/ext/tcpdf/tcpdf.php on line 22164
Warning: array_push() expects parameter 1 to be array, null given in /home/pb_admin/public_html/pb/system/ext/tcpdf/tcpdf.php on line 22164
Warning: array_push() expects parameter 1 to be array, null given in /home/pb_admin/public_html/pb/system/ext/tcpdf/tcpdf.php on line 22164
Notice: Undefined index: thead in /home/pb_admin/public_html/pb/system/ext/tcpdf/tcpdf.php on line 21718

前三个错误是在检查数组元素是否已设置之前尝试访问数组元素的代码问题。由于问题出在/tcpdf/tcpdf.php文件中,我认为你不能解决这个问题。提交TCPDF的错误。

接下来的四个错误很可能是由于前三个错误。修复前三个,接下来的四个错误也很有可能得到解决。

如果您发布错误报告,请在此回答的评论中发布链接。感谢。

答案 3 :(得分:1)

我认为你应该在你的行动中调试0级。 使用Configure :: write(' debug',0);

答案 4 :(得分:0)

你必须在ob_start函数之前通过ob_ *函数捕获所有缓冲区,没有回显或打印或标题:

<?php
ob_start();
[ ... ]
$content_pdf = ob_get_contents();
ob_end_flush();
?>

享受您的代码!

答案 5 :(得分:0)

您应该检查所有开始标记是否都有匹配的结束标记!这是html中最不可疑的错误之一,也许是你得到错误的原因:     “标题已经发送”

答案 6 :(得分:0)

在我的情况下,出现了tcpdf.php中的错误,因为我在HTML中有一些错误 - 一个未关闭的td标记。 看起来像这样的HTML错误会在tcpdf.php文件中引发大量错误,包括那些与实际错误没有任何逻辑链接的错误。

我的建议是通过删除整个&#39; HTML来隔离错误。您发送到输出,只需添加一个字母。如果你得到空的pdf,请开始检查你的html变量。

答案 7 :(得分:0)

遇到同样的问题。这个问题是由于糟糕的HTML,因此TCPDF抛出错误。 修复html问题后,TCPDF对我来说很好,可以修复html问题click here