我有一个由PHP生成的HTML页面,我想输出到PDF。我正在使用mpdf(composer.json:“mpdf / mpdf”:“^ 7.0”)并且我添加了调试变量以查看为什么生成的PDF不正确(虽然HTML看起来很好)。在我的php错误日志中,我看到了:
<?php
.
.
.
ob_start();
?>
(html goes here)
<?php
// We're done! Save the cached content to a file
$fp = fopen($cachefile, 'w');
$html=ob_get_contents();
fwrite($fp, $html);
fclose($fp);
// This sends output to browser
//ob_end_flush();
ob_end_clean();
$log->debug('Cache file created', array('cacheFile' => $cachefile));
$mpdf = new \Mpdf\Mpdf([
'debug' => true,
'format' => 'letter-L',
'margin_left' => 13,
'margin_right' => 13,
'margin_top' => 13,
'margin_bottom' => 13,
'tempDir' => '../../../../private/contest/tmp',
'orientation' => 'L']);
$mpdf->WriteHTML(utf8_encode($html));
$mpdf->Output($$html ,\Mpdf\Output\Destination::INLINE);
但它没有明确说明未定义的变量是什么(我的PHP页面中的第529行对应于mpdf输出调用)。我的PHP代码(还包括将HTML缓存到文件以减少数据库调用)是这样的:
[05-Mar-2018 10:58:53 America/Toronto] PHP Warning: Header may not contain more than a single header, new line detected in /Users/rwaddell/Dropbox/htdocs/wonderfest/private/contest/include/vendor/mpdf/mpdf/src/Mpdf.php on line 9308
如何进一步调试?
修改 Nawin发现双重'$'引发了未捕获的异常,但在修复之后我仍然在PHP错误日志中看到警告:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Contest Entry Form</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="robots" content="noindex,nofollow">
<link rel="icon" href="https://wonderfest.com/wp-content/uploads/2017/01/favicon.ico" type="image/x-icon"/>
<link href="../css/printout.css" type="text/css" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/css?family=Libre+Barcode+39+Extended|Oxygen+Mono|Roboto" rel="stylesheet">
<!--<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
不确定这是否重要。
但是,PDF输出仍然与原始HTML不匹配 - 我是否必须明确传入CSS文件?字体怎么样?我不知道它是否正在使用我的字体或进行替换。我在标签中链接到Google的免费字体(Roboto,Oxygen Mono&amp; Libre Barcode 39 Extended):
1
0,3,4
1,3
1,3,15,12