当前位置:网站首页>Print. JS -- web page file printing
Print. JS -- web page file printing
2022-07-03 14:06:00 【Cupid510】
Print.js
There are four types of printed documents available :’ pdf ‘,’ html ',' Images ’ and json.
The default type is ’ pdf '.
Its basic usage is to call printJS() Just enter one PDF Document URL :printJS('docs/PrintJS.pdf ').
For image files , The idea is the same , But you need to pass the second parameter :printJS('images/PrintJS.jpg ‘,’ image ‘).
To print HTML Elements , In a similar way , Incoming elements id And type :printJS(’ myelementtid ‘,’ html ‘).
Print JSON Data time , Pass in the data to be printed 、 Type and data attributes : printJS({ Printable :myData, type :’ json ', attribute :[‘prop1
‘,’ prop2 ‘,’ prop3’]});
Download and install
npm/yarn install
npm install print-js --save
yarn add print-js
Introduce in the project
import print from ‘print-js’
use cdn It can also be introduced directly
https://printjs-4de6.kxcdn.com/print.min.js
https://printjs-4de6.kxcdn.com/print.min.css
Getting started
Introduce <script src="print.js"></script>
If you use modal Need to introduce css file <link rel="stylesheet" type="text/css" href="print.css">
Document printing
Add a button to print PDF file :
<button type="button" onclick="printJS('docs/printjs.pdf')">
Print PDF
</button>

For large documents , You can display a message to the user when the file is loaded
<button type="button" onclick="printJS({printable:'docs/xx_large_printjs.pdf', type:'pdf', showModal:true})">
Print PDF with Message
</button>
Support base64 PDF Print :
<button type="button" onclick="printJS({printable: base64, type: 'pdf', base64: true})">
Print PDF with Message
</button>
HTML Print
Sometimes we just want to print HTML Selected parts of the page , It can be tricky . Use Print.js, We can easily pass the elements we want to print id. The element can be any label , As long as it has a unique id. The library will try to print it very close to what it looks like on the screen , meanwhile , It will create a printer friendly format for it .
Form printing


Printing with parameters , Such as the title
<button type="button" onclick="printJS({ printable: 'printJS-form', type: 'html', header: 'PrintJS - Form Element Selection' })">
Print Form with Header
</button>
Image printing
Picture printing
printJS('images/print-01-highres.jpg', 'image')
add headers
printJS({
printable: 'images/print-01-highres.jpg', type: 'image', header: 'My cool image header'})
Print multiple pictures
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 Print
someJSONdata = [
{
name: 'John Doe',
email: '[email protected]',
phone: '111-111-1111'
},
{
name: 'Barry Allen',
email: '[email protected]',
phone: '222-222-2222'
},
{
name: 'Cool Dude',
email: '[email protected]',
phone: '333-333-3333'
}
]
basic
<button type="button" onclick="printJS({printable: someJSONdata, properties: ['name', 'email', 'phone'], type: 'json'})">
Print JSON Data
</button>
Custom style
<button type="button" onclick="printJS({
printable: someJSONdata,
properties: ['name', 'email', 'phone'],
type: 'json',
gridHeaderStyle: 'color: red; border: 2px solid #3971A5;',
gridStyle: 'border: 2px solid #3971A5;'
})">
Print JSON Data
</button>
Custom table title name
<button type="button" onclick="printJS({
printable: someJSONdata,
properties: [
{
field: 'name', displayName: 'Full Name'},
{
field: 'email', displayName: 'E-mail'},
{
field: 'phone', displayName: 'Phone'}
],
type: 'json'
})">
Print with custom table header text
</button>
Add table title text
<button type="button" onclick="printJS({
printable: someJSONdata,
type: 'json',
properties: ['name', 'email', 'phone'],
header: '<h3 class="custom-h3">My custom header</h3>',
style: '.custom-h3 { color: red; }'
})">
Print header raw html
</button>
边栏推荐
- jvm-类加载
- Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases
- 3D视觉——2.人体姿态估计(Pose Estimation)入门——OpenPose含安装、编译、使用(单帧、实时视频)
- 核酸修饰的金属有机框架药物载体|PCN-223金属有机骨架包载Ad金刚烷|ZIF-8包裹阿霉素(DOX)
- Go language web development series 26: Gin framework: demonstrates the execution sequence of code when there are multiple middleware
- Analysis of the characteristics of page owner
- windos 创建cordova 提示 因为在此系统上禁止运行脚本
- Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
- 全局事件总线
- “又土又穷”的草根高校,凭什么被称为“东北小清华”?
猜你喜欢

Example analysis of QT learning 18 login dialog box

Ocean CMS vulnerability - search php

JVM class loading

【吉林大学】考研初试复试资料分享

Use and design of Muduo buffer class

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
![[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes](/img/f3/a219fe8e7438b8974d2226b4c3d4a4.png)
[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes

QT learning 22 layout manager (I)

The small project (servlet+jsp+mysql+el+jstl) completes a servlet with login function, with the operation of adding, deleting, modifying and querying. Realize login authentication, prevent illegal log

jvm-类加载
随机推荐
PHP maze game
GoLand 2021.2 configure go (go1.17.6)
RocksDB LRUCache
Field problems in MySQL
Go language unit test 5: go language uses go sqlmock and Gorm to do database query mock
How to promote the progress of project collaboration | community essay solicitation
QT learning 17 dialog box and its types
Go language web development series 28: solve cross domain access of CORS with gin contrib / CORS
Metal organic framework MOFs loaded with non steroidal anti-inflammatory drugs | zif-8 wrapped Prussian blue loaded quercetin (preparation method)
Cross linked cyclodextrin metal organic framework loaded methotrexate slow-release particles | metal organic porous material uio-66 loaded with flavonoid glycosides | Qiyue
Qt学习20 Qt 中的标准对话框(中)
JVM object lifecycle
page owner特性浅析
树的深入和广度优先遍历(不考虑二叉树)
Go language web development series 26: Gin framework: demonstrates the execution sequence of code when there are multiple middleware
windos 创建cordova 提示 因为在此系统上禁止运行脚本
Example analysis of QT learning 18 login dialog box
Uniapp skills - dom display and hiding
FPGA test method takes mentor tool as an example
Uniapp tips - set background music