Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

html-pdf

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-pdf

HTML to PDF converter that uses phantomjs

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
128K
increased by5.4%
Maintainers
1
Weekly downloads
 
Created

What is html-pdf?

The html-pdf npm package allows you to convert HTML content into PDF documents. It is useful for generating PDFs from web pages, HTML strings, or even local HTML files. The package provides a simple API to customize the PDF output, including options for page size, margins, headers, footers, and more.

What are html-pdf's main functionalities?

Convert HTML String to PDF

This feature allows you to convert an HTML string directly into a PDF file. The code sample demonstrates how to create a simple PDF from an HTML string and save it to a file.

const pdf = require('html-pdf');
const html = '<h1>Hello, World!</h1>';
pdf.create(html).toFile('./output.pdf', function(err, res) {
  if (err) return console.log(err);
  console.log(res); // { filename: '/path/to/output.pdf' }
});

Convert HTML File to PDF

This feature allows you to convert an HTML file into a PDF. The code sample demonstrates how to read an HTML file from the filesystem and convert it into a PDF file.

const pdf = require('html-pdf');
const fs = require('fs');
const html = fs.readFileSync('./template.html', 'utf8');
pdf.create(html).toFile('./output.pdf', function(err, res) {
  if (err) return console.log(err);
  console.log(res); // { filename: '/path/to/output.pdf' }
});

Custom PDF Options

This feature allows you to customize the PDF output by specifying options such as page format, orientation, and margins. The code sample demonstrates how to create a PDF with custom options.

const pdf = require('html-pdf');
const html = '<h1>Hello, World!</h1>';
const options = { format: 'Letter', orientation: 'portrait', border: '1in' };
pdf.create(html, options).toFile('./output.pdf', function(err, res) {
  if (err) return console.log(err);
  console.log(res); // { filename: '/path/to/output.pdf' }
});

Add Headers and Footers

This feature allows you to add headers and footers to the PDF. The code sample demonstrates how to include custom header and footer content in the PDF output.

const pdf = require('html-pdf');
const html = '<h1>Hello, World!</h1>';
const options = {
  header: { height: '45mm', contents: '<div style="text-align: center;">Author: John Doe</div>' },
  footer: { height: '28mm', contents: '<span style="color: #444;">{{page}}</span>/<span>{{pages}}</span>' }
};
pdf.create(html, options).toFile('./output.pdf', function(err, res) {
  if (err) return console.log(err);
  console.log(res); // { filename: '/path/to/output.pdf' }
});

Other packages similar to html-pdf

Keywords

FAQs

Package last updated on 26 Apr 2014

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