-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
36 lines (33 loc) · 1.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import {
printHTML
} from "../src"
document.getElementById('print').addEventListener('click', () => {
const html = document.getElementById('html').value,
css = document.getElementById('css').value,
title = document.getElementById('title').value,
htmlDoc = `
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>${title}</title>
<style>${css}</style>
<head>
<body>${html}</body>
</html>`,
printCallback = iframeWin => {
const pageCount = iframeWin.document.querySelectorAll('[data-vivliostyle-page-container]').length
console.log(`page count: ${pageCount}`)
iframeWin.print()
},
errorCallback = message => {
alert(message)
}
printHTML(htmlDoc, {
title,
printCallback,
errorCallback,
hideIframe: true, // Whether to use a hidden iframe (default: true)
removeIframe: true // Whether to remove the iframe after use (default: true)
})
})