可自定义 多元素打印插件 jQuery printThis

  • 源码大小:412KB
  • 所需积分:1积分
  • 源码编号:19JP-3542
  • 浏览次数:224次
  • 最后更新:2023年06月24日
  • 所属栏目:其他
本站默认解压密码:19jp.com 或 19jp_com

简介

jQuery的另一个页面打印插件,允许用户打印网页的特定元素,同时保留页面样式(甚至额外的CSS)和输入/表单值。

更多功能:

  • 自动删除内联样式。
  • 支持打印延迟。
  • 自定义页眉和页面标题。

参见:

  • 打印特定元素的7个最佳JavaScript打印插件

安装:

# NPM
$ npm install print-this

# Bower
$ bower install print-this

如何使用它:

1.将jQuery库和jQuery打印这个插件的脚本放在关闭的body标记之前:

<script src="//code.jquery.com/jquery.min.js"></script>
<script src="printThis.js"></script>

2.附加功能打印此在任何要打印的元素上。

$('form,h1,p').printThis();

3.自定义打印插件的可能选项。

$('SELECTORS').printThis({

  // shows debug info
  debug: false,

  // import page CSS
  importCSS: true,

  // import styles
  importStyle: false,

  // print outer container
  printContainer: true, 

  // additonal CSS file
  loadCSS: "", 

  // page title
  pageTitle: "",

  // remove inline styles
  removeInline: false, 

  // custom selectors to filter inline styles. removeInline must be true
  removeInlineSelector: "body *", 

  // print delay in ms
  printDelay: 333,

  // header 
  header: null,

  // footer
  footer: null,    

  // preserve input/form values
  formValues: true, 

  // preserve the base tag (if available)
  base: false,

  // copy canvas elements (experimental)
  canvas: false,

  // html doctype
  doctypeString: '<!DOCTYPE html>', 

  // remove script tags before appending
  removeScripts: false,

  // copy classes from the html & body tag
  copyTagClasses: false,

  // copy styles from html & body tag (for CSS Variables)
  copyTagStyles: false,
  
});

4.提供回调功能。

$('SELECTORS').printThis({

  // callback function for printEvent in iframe
  beforePrintEvent: null,         

  // function called before iframe is filled
  beforePrint: null,              

  // function called before iframe is removed
  afterPrint: null                
  
});

更新日志:

v2.0.0版本(2022-06-04)

  • 重大更新

v1.16.0 (2022-05-30)

  • beforePrintEvent修复程序

v1.15.1 (2019-08-05)

  • beforePrintEvent修复程序

v1.14.1 (2018-11-04)

  • 固定画布选项仅显示第一个画布

v1.14.0 (2018-07-16)

  • eakkew对打印事件处理程序的合并支持
  • 包含CSS变量的修复程序(通过HTML标记上设置的内联样式)

2018-01-11

  • V1.12.2-顶级Canvas支持的合并修复程序

2017-12-18

  • V1.12.1-针对jQuery版本限制的合并修复程序

2017-10-30

  • V1.12.0-使用克隆(true)复制表单值

2017-08-02

  • V1.11.0-添加copyBodyClasses功能;添加copyTagClasses

2017-04-10

  • V1.10.0-添加了默认禁用的操作,以避免将不需要的脚本带入打印iframe;删除了未记录的辅助函数$.fn.outer。

2017-03-07

  • V1.9.0-画布更新

2017-01-17

  • V1.9.0-画布更新

2017-01-17

  • V1.8.0-添加了“页脚”

2016-12-15

  • 添加基本URL支持和增量版本

预览截图