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

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

简介

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

更多功能:

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

参见:

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

安装:

  1. # NPM
  2. $ npm install print-this
  3.  
  4. # Bower
  5. $ bower install print-this

如何使用它:

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

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

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

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

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

  1. $('SELECTORS').printThis({
  2.  
  3. // shows debug info
  4. debug: false,
  5.  
  6. // import page CSS
  7. importCSS: true,
  8.  
  9. // import styles
  10. importStyle: false,
  11.  
  12. // print outer container
  13. printContainer: true,
  14.  
  15. // additonal CSS file
  16. loadCSS: "",
  17.  
  18. // page title
  19. pageTitle: "",
  20.  
  21. // remove inline styles
  22. removeInline: false,
  23.  
  24. // custom selectors to filter inline styles. removeInline must be true
  25. removeInlineSelector: "body *",
  26.  
  27. // print delay in ms
  28. printDelay: 333,
  29.  
  30. // header
  31. header: null,
  32.  
  33. // footer
  34. footer: null,
  35.  
  36. // preserve input/form values
  37. formValues: true,
  38.  
  39. // preserve the base tag (if available)
  40. base: false,
  41.  
  42. // copy canvas elements (experimental)
  43. canvas: false,
  44.  
  45. // html doctype
  46. doctypeString: '<!DOCTYPE html>',
  47.  
  48. // remove script tags before appending
  49. removeScripts: false,
  50.  
  51. // copy classes from the html & body tag
  52. copyTagClasses: false,
  53.  
  54. // copy styles from html & body tag (for CSS Variables)
  55. copyTagStyles: false,
  56. });

4.提供回调功能。

  1. $('SELECTORS').printThis({
  2.  
  3. // callback function for printEvent in iframe
  4. beforePrintEvent: null,
  5.  
  6. // function called before iframe is filled
  7. beforePrint: null,
  8.  
  9. // function called before iframe is removed
  10. afterPrint: null
  11. });

更新日志:

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支持和增量版本

预览截图