(转)利用wkhtmltox将网页转换为pdf
By
admin
at 2020-12-20 • 2人收藏 • 1288人看过
转自: https://suiang.cn/aardio/samples/wkhtmltox.html 感谢xauto提供
//打印日志 _URL = "https://suiang.cn/aardio/lib/wkhtmltox.tar.lzma" _IMPORTURL["wkhtmltox"] = _URL import console import process; import wkhtmltox; console.setTitle("打印日志") var pdf = wkhtmltox( "http://ide.update.aardio.com/log/" , "~\help\update-log.pdf" ) //全局设置 pdf.global.size.pageSize = "A4" pdf.global.margin = { top = "1cm", bottom = "1cm", left = "1cm", right = "1cm" } //对象设置:页眉 pdf.object.header = { fontSize = 6, fontName = "微软雅黑", spacing = 2.0, right = "更 新 日 志", } //对象设置:页脚 pdf.object.footer = { fontSize = 5, fontName = "Cascadia Code", spacing = 2.0, left = "[page]/[topage]", right = "http://ide.update.aardio.com/log", } //回调函数 pdf.onChanged = function(ctr,val){ var msg = { "Loading pages", "Counting pages", "Resolving links", "Loading headers and footers", "Printing pages" } if(val==100) table.remove(msg) console.showLoading( string.format(" %s %s%%", msg[1], val) ); } pdf.onFinished = function(ctr, val){ console.log('Convert pdf done.') } //转换 var ret = pdf.convert() if(ret!=1) console.log("Convert pdf failed!") process.execute("~\help\update-log.pdf");
登录后方可回帖