开发者社区> 问答> 正文

TCPDF错误-“无法加载PDF文档”或“由于不支持的文件类型或文件已损坏而无法打开pdf”

我正在使用TCPDF在Wordpress环境中生成pdf。但是,在本地计算机上下载后加载PDF或打开文件时遇到问题。

以下是我的代码示例:

$stylesheet_root = get_stylesheet_directory();
require_once($stylesheet_root.'/pdf/TCPDF-master/tcpdf.php');

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

$pdf->SetTitle('Report');

$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

$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(2.1);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}

$pdf->AddPage('P');

$pdf->writeHTMLCell(60, 30, '', '20', '<img src="'.$imagehref.'"/> ');

$pdf->MultiCell(90, 30, "\n\n\n" . 'REPORT', 0, 'L', 0, 1, '', '', true);

// Multicell test
$pdf->MultiCell(10, 15, 'S/No', 1, 'C', 1, 0, '', '', true);
$pdf->MultiCell(25, 15, 'Total Price', 1, 'C', 1, 1, '', '', true);

$pdf->MultiCell(10, 30, $count, 0, 'C', 0, 0, $x, $y, true);
$pdf->MultiCell(25, 30, 'S$ ' . $totalProductPrice, 0, 'C', 0, 1, '', '', true);

// reset pointer to the last page
$pdf->lastPage();

ob_clean();
$pdf->Output('example_007.pdf', 'D');
ob_end_clean();

展开
收起
社区秘书 2019-12-10 10:20:07 1513 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
对象存储实战指南-试读 立即下载
OpenAnolis 龙蜥操作系统开源社区技术创新白皮书 立即下载
使用CNFS搭建弹性Web服务 立即下载