
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
html-pdf-viewer
Advanced tools
Client-side rendering of html to pdf with display and save options using html2canvas and jspdf.
Install html-pdf-viewer and its dependencies using NPM with npm install --save html-pdf-viewer
.
import htmlpdfviewer from 'html-pdf-viewer';
Simplest way to use:
var html = document.getElementById('html');
htmlpdfviewer(html);
Using mode: 'display'
to display it on a page:
var html = document.getElementById('html');
htmlpdfviewer(html, { output: { mode: 'display', container: '#iframeId', height: 800 } });
<iframe src="" id="iframeId" frameBorder="0"></iframe>
See examples.
Implementation in ReactJS:
viewPdf = () => {
htmlpdfviewer(this.html, { output: { mode: 'display', container: '#iframeId', height: 800 } });
}
* * *
<div ref={(html) => { this.html = html }}>
<h2 classname="ui header">Hello world!</h2>
</div>
<iframe src="" id="iframeId" frameBorder="0"></iframe>
<Button onClick={() => this.viewPdf()} type="button">View PDF</Button>
html-pdf-viewer can be configured by adding an optional options
parameter: htmlpdfviewer(<source>, {<options>});
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] . |
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 html2canvas (see here for usage). |
jsPDF | object | { } | Configuration options sent directly to jsPDF (see here for usage). |
output | object | { } | Configuration options for saving/displaying the pdf. mode : 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
FAQs
Client-side rendering of html-pdf-viewer
The npm package html-pdf-viewer receives a total of 30 weekly downloads. As such, html-pdf-viewer popularity was classified as not popular.
We found that html-pdf-viewer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.