簡體   English   中英

TCPDF在生成要打印的表結構時返回錯誤

[英]TCPDF returning error while generating table structure to print

我正在使用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] => 
)

為什么會發生這種錯誤?

TCPDF需要100%有效的XHTML語法

即使是“HTML Tidy”也不會向您顯示所有的HTML錯誤。 在我的情況下,我有一個tr標簽沒有關閉,並在我糾正這個警告消失后,但pdf文件很難看。 例如,通過colspan=”12”改變colspan=12並且通過rowspan=”2” rowspan=2來解決該問題。

嘗試插入......

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

如果這不起作用,請嘗試使用ob_clean(); 代替。

就在你做之前:

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

發生錯誤是因為TCPDF在最終呈現完成之前拋出錯誤。 為了防止TCPDF創建不起作用的PDF,它決定崩潰。

萬一TCPDF不再喜歡你了,看看DomPDF :)

問題是您的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的錯誤。

接下來的四個錯誤很可能是由於前三個錯誤。 修復前三個,接下來的四個錯誤也很有可能得到解決。

如果您發布了錯誤報告,請在此回答的評論中發布鏈接。 謝謝。

我認為你應該在你的行動中調試0級。 使用Configure :: write('debug',0);

你必須在ob_start函數之前通過ob_ *函數捕獲所有緩沖區,沒有echo或print或header:

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

享受你的代碼!

您應該檢查所有開始標記是否具有匹配的結束標記! 這是html中最不可疑的錯誤之一,可能是你收到錯誤的原因:“標題已經發送”

在我的情況下,出現了tcpdf.php中的錯誤,因為我在HTML中有一些錯誤 - 一個未封閉的td標簽。 看起來像這樣的HTML錯誤會在tcpdf.php文件中引發大量錯誤,包括那些與實際錯誤沒有任何邏輯鏈接的錯誤。

我的建議是通過刪除發送到輸出的整個'html'來隔離錯誤,只需添加一個字母。 如果你得到空的pdf,開始檢查你的html變量。

遇到過同樣的問題。 這個問題是由於糟糕的HTML,因此TCPDF拋出錯誤。 修復html問題后,TCPDF對我來說很好,修復html問題點擊這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM