【发布时间】:2015-06-18 19:55:13
【问题描述】:
我需要将 url 转换为 pdf
我尝试使用 tcpdf,但出现如下错误: 注意:未定义的偏移量:第 17218 行 /opt/lampp/htdocs/IBI/tcpdf/tcpdf.php 中的 4 TCPDF ERROR: 部分数据已输出,无法发送 PDF 文件
我认为问题在于页面有html和js和CSS
这是尝试过的代码和网址:
// Include the main TCPDF library (search for installation path).
require_once('tcpdf_include.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 006');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 006', 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(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// set font
$pdf->SetFont('dejavusans', '', 10);
// add a page
$pdf->AddPage();
// test some inline CSS
$html = file_get_contents("http://dvns.me/mahmoud/IBI/");
$pdf->writeHTML($html, true, false, true, false, '');
//Close and output PDF document
$pdf->Output(time().'.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+
【问题讨论】:
-
您可以检查您的标头是否已发送? reference
headers_sent -
@huggilou 在哪里查看?在代码的第一个还是最后?
-
$pdt->Output()function 之前 -
@huggilou 我尝试添加 echo headers_sent();在输出 ($pdf->Output(time().'.pdf', 'I');) 之前并打印 true,这意味着发送了标头
-
也许您在开始 PHP 标记“
标签: javascript php html pdf tcpdf