js 火狐 打印 禁止 空白页_一个精悍的Javascript库,实现Web打印(print.js)

下载地址在github,文末有使用方法

github地址:https://github.com/crabbly/Print.js/

官网:https://printjs.crabbly.com/(可能被墙)

无法访问可以加企鹅群看离线版:1006429377

或者访问:https://www.yuque.com/caiyongjie/snknlo/ga5ef9

8e27172a0b3ea1b2c30715949692e794.png

官网截图

简介

  • 原文:

Print.js was primarily written to help us print PDF files directly within our apps, without leaving the interface, and no use of embeds. For unique situations where there is no need for users to open or download the PDF files, and instead, they just need to print them.

One scenario where this is useful, for example, is when users request to print reports that are generated on the server side. These reports are sent back as PDF files. There is no need to open these files before printing them. Print.js offers a quick way to print these files within our apps.

  • 谷歌翻译:

Print.js主要是为了帮助我们直接在我们的应用程序中打印PDF文件,而无需离开界面,也不使用嵌入。 对于不需要用户打开或下载PDF文件的独特情况,相反,他们只需要打印它们。

例如,当用户请求打印在服务器端生成的报告时,这种情况很有用。 这些报告以PDF文件形式发回。 打印前无需打开这些文件。 Print.js提供了一种在我们的应用程序中打印这些文件的快捷方式。

  • 注意的地方:

PDF files must be served from the same domain as your app is hosted under. Print.js uses iframe to load files before printing them, therefore, it is limited by the Same Origin Policy. This helps preventing Cross-site scripting (XSS) attacks.

必须在托管应用程序的同一域中提供PDF文件。 Print.js在打印文件之前使用iframe加载文件,因此它受同源策略的限制。 这有助于防止跨站点脚本(XSS)攻击。

初体验

首先在页面上添加一个按钮

  • 打印PDF(注意:火狐不支持iframes,可以使用新标签页)
 Print PDF 
  • 打印大文件(可以弹出提示消息)
 Print PDF with Message 
  • html打印
 
... Print Form
  • 打印带头部
  Print Form with Header 
  • 打印图片
 printJS('images/print-01-highres.jpg', 'image') printJS({printable: 'images/print-01-highres.jpg', type: 'image', header: 'My cool image header'})
  • 带头
 printJS({ printable: ['images/print-01-highres.jpg', 'images/print-02-highres.jpg', 'images/print-03-highres.jpg'], type: 'image', header: 'Multiple Images', imageStyle: 'width:50%;margin-bottom:20px;' })
  • 从JSON数据
 someJSONdata = [ { name: 'John Doe', email: 'john@doe.com', phone: '111-111-1111' }, { name: 'Barry Allen', email: 'barry@flash.com', phone: '222-222-2222' }, { name: 'Cool Dude', email: 'cool@dude.com', phone: '333-333-3333' } ]  Print JSON Data 
  • 自定义CSS
  Print JSON Data 
  • 自定义头
  Print with custom table header text My custom header',style: '.custom-h3 { color: red; }' })">Print header raw html

安装使用

 npm install print-js --save//或 yarn add print-js
import print from 'print-js'
 //cdn,不知道能不能访问,我这可以访问 https://printjs-4de6.kxcdn.com/print.min.js https://printjs-4de6.kxcdn.com/print.min.cssye 
  • 如果您将使用模态功能,还包括页面上的Print.css。
 

详细配置:

62fdbe3c2f393f3d86b9cd0c15f07829.png
eafe4a4fb23171a323682ca4aec88231.png
0f64837ae9690217c1c00750cfcbb64b.png
2e1aab1e0f2fbd91a1d4e64082ba43c8.png

兼容性

57dfd30fe37c420a0e23fca623eea105.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值