Client-side rendering of html-pdf-viewer
npm install html-pdf-viewer#### NPM
Install html-pdf-viewer and its dependencies using NPM with npm install --save html-pdf-viewer.
``js`
import htmlpdfviewer from 'html-pdf-viewer';
Simplest way to use:
`js
var html = document.getElementById('html');
htmlpdfviewer(html);
`
Using mode: 'display' to display it on a page:
`js
var html = document.getElementById('html');
htmlpdfviewer(html, { output: { mode: 'display', container: '#iframeId', height: 800 } });
`
See examples.
Implementation in ReactJS:
`js
viewPdf = () => {
htmlpdfviewer(this.html, { output: { mode: 'display', container: '#iframeId', height: 800 } });
}
*
`
html-pdf-viewer can be configured by adding an optional options parameter: htmlpdfviewer(
`js`
htmlpdfviewer(html, {
margin: 1,
filename: 'myfile.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { dpi: 192, letterRendering: true },
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' },
output: { mode: 'display', container: '#iframeId', height: 800 }
});
The options parameter has the following optional fields:
|Name |Type |Default |Description |
|------------|----------------|------------------------------|------------------------------------------------------------------------------------------------------------|
|margin |number or array |0 |PDF margin (in jsPDF units). Can be a single number, [top&bottom, left&right], or [top, left, bottom, right]. |html2canvas
|filename |string |'file.pdf' |The default filename of the exported PDF. |
|image |object |{type: 'jpeg', quality: 0.95} |The image type and quality used to generate the PDF. |
|enableLinks |boolean |true |If enabled, PDF hyperlinks are automatically added ontop of all anchor tags. |
|html2canvas |object |{ } |Configuration options sent directly to (see here for usage).|jsPDF
|jsPDF |object |{ } |Configuration options sent directly to (see here for usage).|mode
|output |object |{ } |Configuration options for saving/displaying the pdf. : save or display. container: Iframe element id on where you want to display the PDF. height: Display height of the iframe. |
NOTE: container is required if you choose mode: display`.
Copyright (c) 2017 Jefferson Aux