gpt4 book ai didi

javascript - 在 PHP 中将 HTML 页面保存为 PDF

转载 作者:行者123 更新时间:2023-11-28 10:53:06 24 4
gpt4 key购买 nike

我需要将 url 转换为 pdf

我尝试使用 tcpdf 但出现如下错误:注意: undefined offset :4 in/opt/lampp/htdocs/IBI/tcpdf/tcpdf.php on line 17218TCPDF 错误:部分数据已输出,无法发送 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
//============================================================+

最佳答案

尝试在 require() 之前插入 ob_clean(),例如

ob_clean()
// set document information
$pdf->SetCreator(PDF_CREATOR);

请参阅reference hererelated issue here .

关于javascript - 在 PHP 中将 HTML 页面保存为 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29606452/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com