当前位置:网站首页>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>
边栏推荐
- Go language unit test 3: go language uses gocovey library to do unit test
- Windos creates Cordova prompt because running scripts is prohibited on this system
- Folic acid modified metal organic framework (zif-8) baicalin loaded metal organic framework composite magnetic material (AU- [email
- Golang — template
- PhpMyAdmin stage file contains analysis traceability
- Webpage connection database ~ simple implementation of addition, deletion, modification and query complete code
- Failure of vector insertion element iterator in STL
- Message subscription and publishing
- Reflection -- basic usage
- Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases
猜你喜欢

Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
[email "/>Doxorubicin loaded on metal organic framework MIL-88 DOX | folic acid modified uio-66-nh2 doxorubicin loaded [email

解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)

Current situation, analysis and prediction of information and innovation industry

Qt学习25 布局管理器(四)

GoLand 2021.1.1: configure the multi line display of the tab of the open file

SQL Injection (GET/Search)
[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)"/>MIL-100( Fe) 包裹小分子阿司匹林形成[email protected](Fe)|甘草次酸修饰金属有机框架材料UiO-66-NH2(简称UiO-66-NH2-GA)

Uio-66-cooh loaded bendamostine | hydroxyapatite (HA) coated MIL-53 (FE) nanoparticles | baicalin loaded manganese based metal organic skeleton material

3D vision - 2 Introduction to pose estimation - openpose includes installation, compilation and use (single frame, real-time video)
随机推荐
JVM runtime data area
[技術發展-24]:現有物聯網通信技術特點
QT learning 21 standard dialog box in QT (Part 2)
Using registered classes to realize specific type matching function template
QT learning 24 layout manager (III)
交联环糊精金属有机骨架负载甲氨蝶呤缓释微粒|金属-有机多孔材料UiO-66负载黄酮苷类药物|齐岳
JVM family - overview, program counter day1-1
Multi person collaborative data annotation based on Baidu brain easydata from scratch
JVM class loading
3D视觉——2.人体姿态估计(Pose Estimation)入门——OpenPose含安装、编译、使用(单帧、实时视频)
Collection of mobile adaptation related articles
Formation of mil-100 (FE) coated small molecule aspirin [email protected] (FE) | glycyrrhetinic acid modified metal organ
Uniapp skills - dom display and hiding
28: Chapter 3: develop Passport Service: 11: define attributes in the configuration file, and then obtain them in the code;
[understanding by chance-37]: the structure of human sensory system determines that human beings are self-centered
Configure stylelint
Summary of common error reporting problems and positioning methods of thrift
GoLand 2021.1.1: configure the multi line display of the tab of the open file
Golang - command line tool Cobra
Uio-66-cooh loaded bendamostine | hydroxyapatite (HA) coated MIL-53 (FE) nanoparticles | baicalin loaded manganese based metal organic skeleton material