当前位置:网站首页>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>
边栏推荐
- How to use lxml to judge whether the website announcement is updated
- Field problems in MySQL
- [acnoi2022] guess numbers
- Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
- Metal organic framework (MOFs) antitumor drug carrier | pcn-223 loaded with metronidazole | uio-66 loaded with ciprofloxacin hydrochloride( QT learning 21 standard dialog box in QT (Part 2)
- 记录关于银行回调post请求405 问题
- 核酸修饰的金属有机框架药物载体|PCN-223金属有机骨架包载Ad金刚烷|ZIF-8包裹阿霉素(DOX)
- Software testing is so hard to find, only outsourcing offers, should I go?
- Richview trvstyle liststyle list style (bullet number)
猜你喜欢
Configure stylelint
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)
Using registered classes to realize specific type matching function template
使用vscode查看Hex或UTF-8编码
Ocean CMS vulnerability - search php
UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
[bw16 application] instructions for firmware burning of Anxin Ke bw16 module and development board update
SQL Injection (POST/Select)
QT learning 24 layout manager (III)
随机推荐
[ACNOI2022]猜数
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases
Leetcode-1175. Prime Arrangements
28: Chapter 3: develop Passport Service: 11: define attributes in the configuration file, and then obtain them in the code;
Simulated access
Function calling convention
SQL Injection (AJAX/JSON/jQuery)
Golang - command line tool Cobra
Go language unit test 3: go language uses gocovey library to do unit test
[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes
Thrift threadmanager and three monitors
Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.
Another industry has been broken by Chinese chips. No wonder the leading analog chip companies in the United States have cut prices and sold off
Metal organic framework MOFs loaded with non steroidal anti-inflammatory drugs | zif-8 wrapped Prussian blue loaded quercetin (preparation method)
消息订阅与发布
Go language unit test 4: go language uses gomonkey to test functions or methods
金属有机骨架(MOFs)抗肿瘤药载体|PCN-223装载甲硝唑|UiO-66包载盐酸环丙沙星([email protected])
MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)
28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;