芥子打印组件升级—增加url打印
在BS 流行时代,到处充满网页。有时网页上有打印需求,但是打印模板跟网页不同,是另外一种格式。目前很多解决方案就是另外弄一个工具,定做一个打印模板,打印模板通常不是html格式。增加开发人员学习成本。是否可以直接使用html作为打印模板呢?
经过一段时间努力,芥子打印组件0.3 版实现了这个需求。虽然不是很完美。目前还是够用了。刚开始是用微软浏览器组件,但是这个东西有时不能用,后来没办法放弃了,直接解析html打印。当然离浏览器还有一段距离。毕竟时间那么短。有机会,弄谷歌浏览器组件来解析html就完美!这是后话,下面上代码,贴图。有图有真相。
下载芥子打印组件
打印url demo
下载后运行芥子打印组件,如何运行,参考前一篇文件芥子打印组件。双击testprintcomponent.html(最好用谷歌浏览器打开),点击打印html按钮,如下图:
打印url js方法参数说明
html代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="printcomponent.js"></script>
<script>
$(document).ready(function(){
function printCallback( success,message){
if(success){
alert(message);
}else{
alert(message);
}
}
$("#but1").click(function(){
printHtml('127.0.0.1',1819,newGuid(),'https://jz-fw.com/jsp/printcomponent/prescription.html','FoxitReaderPDFPrinter',DMPAPER_A4,DMORIENT_LANDSCAPE,printCallback);
});
$("#but2").click(function(){
var fileArray=new Array();
fileArray[0]="/root/pdf/1.pdf";
fileArray[1]="/root/pdf/2.pdf";
// fileArray[2]="/root/pdf/3.pdf";
printSftpFiles('127.0.0.1',1819,newGuid(),'x.x.x.x',22,'user-name','xxxxxxxxxxxxxxx',fileArray,'FoxitReaderPDFPrinter'
,DMPAPER_A4,DMORIENT_LANDSCAPE,130,printCallback);
});
$("#but3").click(function(){
var fileArray=new Array();
fileArray[0]="http://abcde.com/examples/pdf/QQSpider.pdf";
fileArray[1]="http://abcde.com/examples/pdf/www.datatables.pdf";
// fileArray[2]="/root/pdf/3.pdf";
printHttpFiles('127.0.0.1',1819,newGuid(),fileArray,'FoxitReaderPDFPrinter'
,DMPAPER_A4,DMORIENT_LANDSCAPE,130,printCallback);
});
});
</script>
</head>
<body>
<div id="div1"><h2>芥子打印组件打印例子</h2></div>
<button id="but1">打印url</button>
<button id="but2">打印sftp pdf</button>
<button id="but3">打印http pdf</button>
</body>
</html>
js 方法
打开printcomponent.js 可以看到js方法:
//--打印网页
//参数说明:
//printComponentIp:打印组件服务器ip 默认为本机:127.0.0.1
//printComponentPort:打印组件服务器端口,默认为80
//id:每次命令请求id,以识别发的命令
//htmlUrl:网页url,即为需要打印网页的url
//pageSize:指定打印的页大小:A4等
//orientation