如何使用Mpdf类在PDF创建中显示包含特殊字符的内容

时间:2014-06-04 07:17:55

标签: php

1.内容未以pdf格式显示

header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/x-download");
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
$pdf =  new mPDF();
$content="'gAAAAgABwESAAMAAAABAAEAAAEaA";
$pdf->WriteHTML($strContent);
$pdf->Output($filename, 'D');

/*content is not displaying in PDF file, But it is displaying in web page when echo the content  */ 

1 个答案:

答案 0 :(得分:0)

首先,您尚未设置正确的内容类型标题,因此PDF将输出到浏览器。

改变这个:

header("Content-Type: application/x-download");

为:

header("Content-Type: application/pdf");

其次,生成PDF的代码看起来不正确。例如,您的html内容位于$content,但是当您在pdf对象上编写时,您正在使用$strContent等...

试试这个:

// Set Header
header("Content-Type: application/pdf");
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');

// Generate & Output PDF
$pdf = new mPDF();
$content="'gAAAAgABwESAAMAAAABAAEAAAEaA";
$pdf->WriteHTML($content);
$pdf->Output();