2024年06月09日 建站教程
功能介绍:利用lodop插件对页面实现有样式或无样式的打印!具体代码如下:
打印与显示样式一致
var LODOP; //声明为全局变量 function myPreview(){ LODOP = getLodop(); var strBodyStyle = "<style>"+document.getElementById("style").innerHTML+"</style>"; var strFormHtml = strBodyStyle+"<body>"+document.getElementById("form").innerHTML+"</body>"; LODOP.PRINT_INIT(""); LODOP.ADD_PRINT_TEXT(50,50,260,39,"打印与显示样式一致"); LODOP.ADD_PRINT_HTM(88,50,300,200,strFormHtml); LODOP.PREVIEW(); };
无样式打印
var LODOP; //声明为全局变量 function myPreview(){ LODOP = getLodop(); var strFormHtml = document.getElementById("form").innerHTML; LODOP.PRINT_INIT(""); LODOP.ADD_PRINT_TEXT(50,50,260,39,"无样式打印"); LODOP.ADD_PRINT_HTM(88,50,300,200,strFormHtml); LODOP.PREVIEW(); };
style设置样式打印
var LODOP; //声明为全局变量 function myPreview(){ LODOP = getLodop(); var strBodyStyle = "<style>table,td { border: 1 solid #000000;border-collapse:collapse }</style>"; var strFormHtml = strBodyStyle+"<body>"+document.getElementById("form").innerHTML+"</body>"; LODOP.PRINT_INIT(""); LODOP.ADD_PRINT_TEXT(50,50,260,39,"style设置样式打印"); LODOP.ADD_PRINT_HTM(88,50,300,200,strFormHtml); LODOP.PREVIEW(); };
引入link样式打印
var LODOP; //声明为全局变量 function myPreview(){ LODOP = getLodop(); var strStyleCSS = "<link href = 'style.css' type = 'text/css' rel = 'stylesheet'>"; var strFormHtml = strStyleCSS+"<body>"+document.getElementById("form").innerHTML+"</body>"; LODOP.PRINT_INIT(""); LODOP.ADD_PRINT_TEXT(50,50,260,39,"引入link样式打印"); LODOP.ADD_PRINT_HTM(88,50,300,200,strFormHtml); LODOP.PREVIEW(); };
本文链接:http://so.lmcjl.com/news/6231/