官方网站: https://phantomjs.org/
js文件生成(convert.js)
// html 转换为 bmp文件
var webPage = require('webpage');
var system = require('system');
var source = system.args[1]; // xxx.html
var target = system.args[2]; // xxx.bmp
var page = webPage.create();
page.open(source, function start(status) {
page.render(target);
phantom.exit();
});
获取目标html中的内容
https://phantomjs.org/api/webpage/method/evaluate.html
使用page.evaluate()
获取html中内容,并使用page.onConsoleMessage
承接显示。
page.onConsoleMessage = function(msg) {
console.log(msg);
}
page.open(source, function start(status) {
page.evaluate(function(){
console.log(document.documentElement.innerHTML);
})
page.render(target);
phantom.exit();
});
运行
CMD运行方式:
phantomjs convert.js xxx.html xxx.bmp
QT调用
QProcess processconvert(this);
QStringList listargs;
listargs << "convert.js" << "report.html" << "report.bmp";
// 重要!!! 设置文件路径目录
processconvert.setWorkingDirectory(strprogram);
processconvert.start("phantomjs.exe", listargs);
processconvert.waitForFinished();
problem:exe执行失败
分配文件权限
QFile::setPermissions(strfilepath, QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner);
设置工作目录
processconvert.setWorkingDirectory(strprogram);
problem: 不支持普通流式布局
https://bleepcoder.com/cn/phantomjs/161082191/flex-flow-row-wrap-does-not-work
.div {
display:flex;
flex-wrap:wrap;
flex-direction: row;
}
改为
.div {
display: -webkit-flex;
-webkit-flex-wrap: wrap;
}