Allows page-layouting using the vivliostyle for printing within a website without destroying the original layout
- Install vivliostyle-print like this within your browser-based JavaScript project:
npm install @vivliostyle/print --save
- Use it within your project like this:
import {printHTML} from '@vivliostyle/print'
const htmlDoc = `<!doctype html>
<html>
<head>
<style>
... Add your CSS code here ...
</style>
</head>
<body>
... Add your HTML code here ...
</body>
</html>`,
config = {
title: 'my printed page',
printCallback: iframeWin => iframeWin.print() // optional: only needed if calling something other than window.print() for printing.
errorCallback: message => alert(message) // optional: only needed if you want to handle errors.
}
printHTML(htmlDoc, config)
You can also take a look at the demo (sourcecode) .
- Download the repo to your local machine, for example using::
git clone https://github.com/vivliostyle/vivliostyle-print.git
- Enter the folder::
cd vivliostyle-print
- Install and build it::
npm install
npm run build_demo
- Serve the demo folder, for example using the simple PHP webserver::
php -S localhost:8000 -t demo/
- Access the demo from a web browser by navigating to http://localhost:8000
On larger projects, it can be difficult to ensure that no developer is accidentally breaking the terms of the Vivliostyle AGPL license. Vivliostyle-print only exposes one of the functions of Vivliostyle that does not allow the sharing of complex data structures between surrounding code and Vivliostyle, which is the most important requirements to follow when using VIvliostyle in combination with a non-open source project. For more information cocnerning the license, read this.
Please report any bugs and open pull requests on the Vivliostyle main repo.