html2pdf php,php - html2pdf = $html2pdf->WriteHTML($VARIABLE); line causing problems - Stack Overflo...

博主在尝试使用HTML2PDF库将用户输入的HTML数据保存为PDF文件时遇到问题。当尝试写入HTML内容时,出现'TCPDF错误:已有数据输出,无法发送PDF文件'的错误。简化代码后可以成功生成PDF,但直接处理用户输入的数据时失败。可能的原因涉及到数据输出的管理或编码问题。解决方案可能涉及清理输出缓冲区或检查用户输入数据的格式。
摘要由CSDN通过智能技术生成

I have a form that takes user input, posts to itself and stores my php code into a string variable and saves that string data to a .html file on my server. I'd like to do away with the .html file and instead save to .pdf with html2pdf but I'm running into an issue.

I have the following code in my php file:

require_once(dirname(__FILE__).'/html2pdf_v4.03/html2pdf.class.php');

$html2pdf = new HTML2PDF('P','Letter','en');

$html2pdf->WriteHTML($current);

$html2pdf->Output('/var/www/Inspection/Quote/exemple.pdf');

When I comment out the third line "$html2pdf->WriteHTML($current);" I get an error of "TCPDF ERROR: Some data has already been output, can't send PDF file".

When I comment out the third and fourth lines the rest of my page carries out without issue. . . I just don't get my .pdf.

I've seen some posts regarding flushing out something right before the write line but none of them were clear enough for me to work through.

Also, if I use a much simplified code I can generate the pdf properly. . . I'm lost as to why this is possible.

Here is what works:

$content = "

Exemple d'utilisation

Ceci est un exemple d'utilisation

de HTML2PDF.

";

require_once(dirname(__FILE__).'/html2pdf_v4.03/html2pdf.class.php');

$html2pdf = new HTML2PDF('P','A4','fr');

$html2pdf->WriteHTML($content);

$html2pdf->Output('exemple.pdf');

* EDIT *

$current =

Sales Order: 1 3

General Order Information
Order Num:1
Order Rev:3
Quote Num:1
Order Date:1970-01-01
Customer Name:1
Customer Buyer:1
Sold By:ED
Sales Rep:DR
Prog Mgr:VJ
Terms:1
FOB:1
Shipping Co:1
Ship Acct Num:1
Shipping Method:1
Order Comments:1
Cust SO Upload:The file 1-1-3.jpg has been uploaded, and Quote 1 has been added to the Quote directory

Line
Cust PN / Rev
PN / Rev
Description
Qty
UOM
Sale Price
Line Total
Required Date
Program

1

1 - 1

1 - 1

1

1

1

1.00

1.00

1970-01-01

1

The Order Total is 1.00

wkhtmltopdf is something I'd like to stay away from as it requires an x-server. . . something I'd like to avoid if possible.

Thanks in advance.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值