New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

html2pdf.js

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html2pdf.js

Client-side HTML-to-PDF rendering using pure JS

  • 0.10.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
203K
decreased by-15.76%
Maintainers
0
Weekly downloads
 
Created

What is html2pdf.js?

html2pdf.js is a JavaScript library that allows you to convert HTML content into PDF documents. It leverages the capabilities of jsPDF and html2canvas to generate high-quality PDFs directly from web pages.

What are html2pdf.js's main functionalities?

Convert HTML to PDF

This feature allows you to convert a specific HTML element into a PDF document and save it. The code sample demonstrates how to select an HTML element with the ID 'content' and convert it to a PDF.

const element = document.getElementById('content');
html2pdf().from(element).save();

Custom PDF Options

This feature allows you to customize various options for the PDF generation, such as margins, filename, image quality, and PDF format. The code sample demonstrates how to set these options and convert an HTML element to a PDF with the specified settings.

const element = document.getElementById('content');
const options = {
  margin: 1,
  filename: 'myfile.pdf',
  image: { type: 'jpeg', quality: 0.98 },
  html2canvas: { scale: 2 },
  jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
};
html2pdf().set(options).from(element).save();

Add Content to PDF

This feature allows you to add custom content to the generated PDF. The code sample demonstrates how to add the text 'Additional content' at coordinates (10, 10) in the PDF before saving it.

const element = document.getElementById('content');
html2pdf().from(element).toPdf().get('pdf').then(function (pdf) {
  pdf.text('Additional content', 10, 10);
  pdf.save('custom.pdf');
});

Other packages similar to html2pdf.js

Keywords

FAQs

Package last updated on 26 Feb 2025

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc