【发布时间】:2018-07-12 09:28:19
【问题描述】:
我正在尝试通过我的 wordpress 插件生成 pdf,但它重复相同的错误。该问题的解决方案是什么? 我已经检查了php标签前后的空白。
require_once(plugin_dir_path(__FILE__) . '/tcpdf/tcpdf.php');
// create new PDF document
$pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
//$pdf->SetAuthor('Our Code World');
$pdf->SetTitle('First printed pdf!');
// set default header data
$pdf->SetHeaderData('', '', PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont('helvetica');
// set margins
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetMargins(PDF_MARGIN_LEFT, '5', PDF_MARGIN_RIGHT);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, 10);
//set font
$pdf->SetFont('helvetica', '', 12);
$pdf->AddPage();
/*
* content run from here
*/
$content = '';
$content .= '
<table border="1" cellspacing="0" cellpadding="5">
<tr>
<th width="5%">ID</th>
<th width="30%">Name</th>
</tr>
';
$content .= '
<tr>
<td>2574</td>
<td>Rafiq</td>
</tr>
';
$content .= '</table>';
$pdf->writeHTML($content);
ob_end_clean();
$pdf->Output("sample.pdf", "I");
【问题讨论】:
-
你能把你的代码贴在这里吗?
-
您是否在此行之前打印或回显
$pdf->Output("sample.pdf", "I");? -
否。有条件执行我的代码。提交表单后出现错误消息。请参阅我的代码的一部分。 data-title="Total">FILE) . '/tcpdf/tcpdf.php'); // 创建新的 PDF 文档 $pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
-
什么是
data-title="Total">? -
它是我文件的 html 块。