我wkhtmltopdf
用来生成我的pdf文件。我已经将这一代人单独留下了一段时间,无论出于何种原因,它不再生成页眉和页脚。
到目前为止我尝试过的事情(当更多答案出现时会更新):
- 在页眉和页脚中添加 ,
doctype
和标签html
head
body
- 将页眉和页脚的路径更改为绝对路径(即使使用来自驱动器前向 C:/xampp... 的完整绝对路径也不起作用。)可能值得指出的是,将文件名更改为不存在的文件名不会抛出错误。所以我不知道它是否找到文件。也许有人可以告诉我一个测试这个的好方法?
这是我的头文件:
<!DOCTYPE html>
<html>
<head>
<title>PDF header</title>
<style>
html {
display: block;
}
body {
font-family: Calibri, "Segoe Ui Regular", sans-serif;
letter-spacing: 0px;
}
</style>
</head>
<body style="padding-top: 30px">
<img src="../../images/logo_extra.jpg" style="width: 100%;"/>
</body>
</html>
这是我的主要文件:
<?php
session_start();
require __DIR__ . '/../vendor/autoload.php';
use Knp\Snappy\Pdf;
$pdf = new Pdf('pdf\wkhtmltopdf\bin\wkhtmltopdf');
header('Content-Type: application/pdf');
// header('Content-Disposition: attachment; filename="offerte.pdf"');
$pdf->setOption('header-html', 'pdf/header.html');
$pdf->setOption('footer-html', 'pdf/footer.html');
$pdf->setOption('load-error-handling','ignore');
// I know there is a 'cover' function in WKHTMLTOPDF
$file = file_get_contents('pdf/cover.php');
echo $pdf->getOutputFromHtml($file);
?>
和往常一样,请 给我一个解释,也许是一个例子,但不仅仅是一堆工作代码!
PS:如果您发现任何其他错误,请告诉我。