小伙伴们,惊喜来啦!Peach-Printer 2.0 摇身一变,解锁超酷 Web 打印转 PDF 功能。
只需要将一下代码示例加入到前段js代码中,就可以将打印内容以PDF格式下载到本地
var template = encodeURIComponent(JSON.stringify("模版JSON对象")) var datasource = encodeURIComponent(JSON.stringify("模版数据源对象")); var license = encodeURIComponent("授权码");//下载PDF文件代码示例 const url = "http://127.0.0.1:9523/printPDF" var httpRequest = new XMLHttpRequest(); httpRequest.open("POST", url, true); httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); httpRequest.responseType = 'blob'; httpRequest.onreadystatechange = () => {if (httpRequest.status == 200) {//pdf字节码bloblet blob = httpRequest.response;} } httpRequest.onerror = function () {alert("Peach-Printer打印控件未启动") }; httpRequest.send("template=" + template + "&license=" + license + "&datasource=" + datasource);
此功能适用于各种需要前段展现防修改的应用场景,后续我们还将加入防伪水印等功能,请关注我们。
官网地址:https://jpeach.xyz/