Bor*_*oso 10 pdf-generation phantomjs
我正在使用phantomjs生成pdf文件,但我想用HTML重复一个已定义的标题,它在没有图像的情况下工作,但是一旦我添加它就不起作用
page.viewportSize = { width: 600, height: 600 };
page.paperSize = {
format: 'A4', orientation: 'portrait', margin: '0px',
header: {
height: "1.2cm",
contents: phantom.callback(function(pageNum, numPages) {
return '<img src="https://www.google.com.bo/images/srpr/logo4w.png" height="0.95cm"/>';
})
},
footer: {
height: "0.7cm",
contents: phantom.callback(function(pageNum, numPages) {
return '<h3 class="header">Footer</h>';
})
}
}
Run Code Online (Sandbox Code Playgroud)
Hacky解决这个问题,通过将img放在body中并使用display:none;来预先缓存页面上的图像.
<img src="https://www.google.com.bo/images/srpr/logo4w.png" height="0.95cm" style="display: none;"/>
Run Code Online (Sandbox Code Playgroud)
然后在标题和/或页脚中也有img标记.
这是必需的,因为页眉和页脚不会等待html在继续光栅之前完成加载.它需要被改进为更多Async并且是一个已知的bug.
由于在页面完全加载后处理页眉和页脚,因此图像将可供他们使用.这也适用于base64图像源.
它适用于https://github.com/ariya/phantomjs/pull/359的补丁
安装它:
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 1.9
edit [remote "origin"] part in .git/config
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = https://github.com/ariya/phantomjs.git
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
git fetch
git merge pr/359
./build.sh
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6943 次 |
| 最近记录: |