首页 > 技术文章 > 使用jQuery插件PrintArea进行html页面打印

leestar54 2014-12-10 12:48 原文

在开发系统时,我们一般会有统计分析的功能需求,而现在大多数系统都是使用B/S的形式开发。

所以,html报表打印,并且打印指定内容,成了必要的功能。

开源地址:https://github.com/RitsC/PrintArea

使用非常简单,在需要打印的div加入class=PrintArea即可。

然后调用$("div.PrintArea").printArea( [OPTIONS] );

其中options默认值为

var defaults = { mode       : modes.iframe,
                     standard   : standards.html5,
                     popHt      : 500,
                     popWd      : 400,
                     popX       : 200,
                     popY       : 200,
                     popTitle   : '',
                     popClose   : false,
                     extraCss   : '',
                     extraHead  : '',
                     retainAttr : ["id","class","style"] };

 

原理也比较简单,重新构造了一个html,调用window.print进行打印,源码很清晰。

推荐阅读