【发布时间】:2012-07-03 18:39:51
【问题描述】:
我有一个表单,它接受用户输入、发布到自身并将我的 php 代码存储到一个字符串变量中,并将该字符串数据保存到我服务器上的一个 .html 文件中。我想删除 .html 文件,而是使用 html2pdf 保存到 .pdf,但我遇到了问题。
我的 php 文件中有以下代码:
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');
当我注释掉第三行“$html2pdf->WriteHTML($current);”我收到“TCPD 错误:某些数据已输出,无法发送 PDF 文件”的错误。
当我注释掉第三行和第四行时,我的页面的其余部分会毫无问题地执行。 . .我只是没有得到我的 .pdf。
我看过一些关于在写入行之前清除某些内容的帖子,但没有一个足够清楚让我能够完成工作。
另外,如果我使用非常简化的代码,我可以正确生成 pdf。 . .我不知道为什么这是可能的。
以下是有效的:
$content = "
<page>
<h1>Exemple d'utilisation</h1>
<br>
Ceci est un <b>exemple d'utilisation</b>
de <a href='http://html2pdf.fr/'>HTML2PDF</a>.<br>
</page>";
require_once(dirname(__FILE__).'/html2pdf_v4.03/html2pdf.class.php');
$html2pdf = new HTML2PDF('P','A4','fr');
$html2pdf->WriteHTML($content);
$html2pdf->Output('exemple.pdf');
* 编辑 * $当前 =
<br><div align="center"><H1><center>Sales Order: <font color="red" style="bold"> 1 3
</font></center></h1>
</div>
<hr width="85%">
<table width="800" align="center">
<tr>
<td valign="top" width="50%" align="center">
<table frame="border">
<th bgcolor="cccccc" colspan="2" align="center">General Order Information</th>
<tr>
<td align="center" nowrap="nowrap" width="40%">Order Num:</td>
<td width="60%">1</td>
</tr>
<tr>
<td align="center" nowrap="nowrap" width="40%">Order Rev:</td>
<td width="20%">3</td>
</tr>
<tr>
<td align="center" nowrap="nowrap" width="40%">Quote Num:</td>
<td width="20%">1</td>
</tr>
<tr>
<td align="center" nowrap="nowrap" width="40%">Order Date:</td>
<td width="60%">1970-01-01</td>
</tr>
<tr>
<td align="center" nowrap="nowrap" width="40%">Customer Name:</td>
<td width="60%">1</td>
</tr>
<tr>
<td align="center" nowrap="nowrap" width="40%">Customer Buyer:</td>
<td width="60%">1</td>
</tr>
<tr>
<td align="center" nowrap="nowrap" width="40%">Sold By:</td>
<td width="60%">ED </td>
</tr>
<tr>
<td align="center" nowrap="nowrap" width="40%">Sales Rep:</td>
<td width="60%">DR</td>
</tr>
<tr>
<td align="center" nowrap="nowrap" width="40%">Prog Mgr:</td>
<td width="60%">VJ</td>
</tr>
</table>
</td>
<!-- Start of Shipping Data -->
<td valign="top" width="50%">
<table align="center" frame="Border">
<th bgcolor="cccccc" colspan="2" align="center">Shipping Information</th>
<tr>
<td align="center" nowrap="nowrap" >Terms:</td>
<td align="left">1</td>
</tr>
<tr>
<td align="center" nowrap="nowrap" >FOB:</td>
<td align="left">1</td>
</tr>
<tr>
<td align="center" nowrap="nowrap" >Shipping Co:</td>
<td align="left">1</td>
</tr>
<tr>
<td nowrap="nowrap" align="center">Ship Acct Num:</td>
<td align="left">1</td>
</tr>
<tr>
<td nowrap="nowrap" align="center">Shipping Method:</td>
<td align="left">1</td>
</tr>
<tr>
<td nowrap="nowrap" align="center" valign="top">Order Comments:</td>
<td>1</td>
</tr>
<tr>
<td nowrap="nowrap" align="center" width="40%">Cust SO Upload:</td>
<td width="60%">The file 1-1-3.jpg has been uploaded, and Quote 1 has been added to the Quote directory </td>
</tr>
</table>
</td>
</tr>
</table>
<hr width="85%"> <table align="center" width="85%" cellpadding="3" cellspacing="0" frame="border" rules="all">
<tr>
<td bgcolor="cccccc" align="center"><h5>Line</h5></td>
<td bgcolor="cccccc" align="center"><h5>Cust PN / Rev</td>
<td bgcolor="cccccc" align="center"><h5>PN / Rev</td>
<td bgcolor="cccccc" align="center"><h5>Description</h5></td>
<td bgcolor="cccccc" align="center"><h5>Qty</h5></td>
<td bgcolor="cccccc" align="center"><h5>UOM</h5></td>
<td bgcolor="cccccc" align="center"><h5>Sale Price</h5></td>
<td bgcolor="cccccc" align="center"><h5>Line Total</h5></td>
<td bgcolor="cccccc" align="center"><h5>Required Date</h5></td>
<td bgcolor="cccccc" align="center"><h5>Program</h5></td>
</tr> <tr>
<td width="3px" valign="top" align="center">
1 </td> <td nowrap="nowrap" valign="top" align="center">
1 - 1
</td>
<td nowrap="nowrap" valign="top" align="center">
1 - 1
</td>
<td nowrap="nowrap" valign="top" align="center">
1
</td>
<td nowrap="nowrap" valign="top" align="center">
1
</td>
<td nowrap="nowrap" valign="top" align="center">
1
</td>
<td nowrap="nowrap" valign="top" align="center">
1.00
</td>
<td nowrap="nowrap" valign="top" align="center">
1.00
</td>
<td nowrap="nowrap" valign="top" align="center">
1970-01-01
</td>
<td nowrap="nowrap" valign="top" align="center">
1
</td>
</tr> <tr>
<td align="right" colspan="10" bgcolor="cccccc">
<b>The Order Total is 1.00</b>
</td>
</tr>
</table>
wkhtmltopdf 是我想远离的东西,因为它需要一个 x 服务器。 . .如果可能的话,我想避免的事情。
提前致谢。
【问题讨论】:
-
你真的有一个变量
$current吗?在您的测试示例中,您使用$content。 -
而且您实际上并没有包含错误消息。
-
我们能看到
$current变量的内容吗? -
我确实有一个变量 $current... 它有点冗长。我已添加到原帖中。