wkhtmltopdf ContentNotFoundError,代码 1
wkhtmltopdf ContentNotFoundError, code 1
我正在尝试使用 wkhtmltopdf phpwrapper 生成基本的 pdf。我也在用yii框架。
这是我的 HTML:
<!doctype html>
<html>
<head>
</head>
<body>
<p>test</p>
</body>
</html>
我在 wktmltopdf 中的设置:
$pdfParams = array(
'header-html' => $this->tmpHeaderFile->getFileName(),
'footer-html' => $this->tmpFooterFile->getFileName(),
'username' => 'myUser',
'password' => 'myPass',
);
$this->pdf = new Pdf($pdfParams);
我得到的错误:
Exception 'Exception' with message 'Could not create PDF: Loading pages (1/6)
[> ] 0%
[======> ] 10%
[==============================> ] 50%
[============================================================] 100%
Counting pages (2/6)
[============================================================] Object 1 of 1
Resolving links (4/6)
[============================================================] Object 1 of 1
Loading headers and footers (5/6)
[===> ] 5%
[======> ] 10%
[======> ] 10%
[=======> ] 13%
[==========> ] 17%
[==================================> ] 57%
[====================================> ] 61%
Warning: Failed to load https://work.mydomain.com/devs/florian/web//devs/florian/web/themes/css/report-footer.css (ignore)
[============================================================] 100%
Printing pages (6/6)
[> ] Preparing
[============================================================] Page 1 of 1
Done
Exit with code 1 due to network error: ContentNotFoundError'
知道问题出在哪里吗?
我以前遇到过类似的问题。使用 wkhtmltopdf 时,您需要确保将所有静态资产添加到 HTML 文件中。
例如:
CSS 个文件,使用内部样式表:
<!doctype html>
<html>
<head>
<style>
html {
margin: 0;
}
</style>
</head>
<body>
<p>test</p>
</body>
</html>
对于 javascript 个文件,也将脚本直接添加到 HTML 个文件中。
<!doctype html>
<html>
<head>
<script type="text/javascript">
var body = document.querySelector('body');
</script>
</head>
<body>
<p>test</p>
</body>
</html>
希望对您有所帮助
我知道我来晚了,但对于未来的读者:在我的例子中,header
模板中有一个损坏的 link。然后当 wkhtmltopdf 尝试加载它时,它中断了...
因此,我会检查损坏的 links:
'header-html' => $this->tmpHeaderFile->getFileName(),
'footer-html' => $this->tmpFooterFile->getFileName(),
我正在尝试使用 wkhtmltopdf phpwrapper 生成基本的 pdf。我也在用yii框架。
这是我的 HTML:
<!doctype html>
<html>
<head>
</head>
<body>
<p>test</p>
</body>
</html>
我在 wktmltopdf 中的设置:
$pdfParams = array(
'header-html' => $this->tmpHeaderFile->getFileName(),
'footer-html' => $this->tmpFooterFile->getFileName(),
'username' => 'myUser',
'password' => 'myPass',
);
$this->pdf = new Pdf($pdfParams);
我得到的错误:
Exception 'Exception' with message 'Could not create PDF: Loading pages (1/6)
[> ] 0%
[======> ] 10%
[==============================> ] 50%
[============================================================] 100%
Counting pages (2/6)
[============================================================] Object 1 of 1
Resolving links (4/6)
[============================================================] Object 1 of 1
Loading headers and footers (5/6)
[===> ] 5%
[======> ] 10%
[======> ] 10%
[=======> ] 13%
[==========> ] 17%
[==================================> ] 57%
[====================================> ] 61%
Warning: Failed to load https://work.mydomain.com/devs/florian/web//devs/florian/web/themes/css/report-footer.css (ignore)
[============================================================] 100%
Printing pages (6/6)
[> ] Preparing
[============================================================] Page 1 of 1
Done
Exit with code 1 due to network error: ContentNotFoundError'
知道问题出在哪里吗?
我以前遇到过类似的问题。使用 wkhtmltopdf 时,您需要确保将所有静态资产添加到 HTML 文件中。
例如: CSS 个文件,使用内部样式表:
<!doctype html>
<html>
<head>
<style>
html {
margin: 0;
}
</style>
</head>
<body>
<p>test</p>
</body>
</html>
对于 javascript 个文件,也将脚本直接添加到 HTML 个文件中。
<!doctype html>
<html>
<head>
<script type="text/javascript">
var body = document.querySelector('body');
</script>
</head>
<body>
<p>test</p>
</body>
</html>
希望对您有所帮助
我知道我来晚了,但对于未来的读者:在我的例子中,header
模板中有一个损坏的 link。然后当 wkhtmltopdf 尝试加载它时,它中断了...
因此,我会检查损坏的 links:
'header-html' => $this->tmpHeaderFile->getFileName(),
'footer-html' => $this->tmpFooterFile->getFileName(),