npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

easyhtml2pdf

v1.0.2

Published

High-level HTML → PDF converter using easyhtml2pdf with full options

Readme

EasyHTML2PDF

EasyHTML2PDF is a Node.js utility for converting HTML content to PDF files with advanced customization options. It supports RTL languages (such as Arabic), custom headers/footers, page formatting, and more. This project is ideal for generating reports, invoices, or any document from HTML.

Features

  • Convert HTML to PDF: Render any HTML string or file as a PDF.
  • RTL Language Support: Easily generate PDFs in right-to-left languages.
  • Custom Page Format: Choose standard formats like A4, Letter, etc.
  • Custom Margins: Set page margins in millimeters.
  • Header & Footer Templates: Add custom HTML headers and footers.
  • Print Backgrounds: Optionally include background graphics/colors.
  • Flexible Output: Save PDFs to any path.

Installation

npm install easyhtml2pdf

Usage

Here’s an example for generating an Arabic PDF report:

const { convertToPdf } = require("easyhtml2pdf");

async function go() {
  const html = `...your HTML content...`;

  await convertToPdf({
    html,
    output: "examples/output_arabic.pdf",
    options: {
      format: "A4",
      printBackground: true,
      margin: { top: "10mm", bottom: "10mm", left: "10mm", right: "10mm" },
      displayHeaderFooter: true,
      headerTemplate: '<div style="font-size:10px; text-align:center; margin-left:20px;">Header</div>',
      footerTemplate: '<div style="font-size:10px; text-align:center; margin-left:20px;">Page<span class="pageNumber"></span> / <span class="totalPages"></span></div>'
    }
  });

  console.log("PDF created: examples/output_arabic.pdf");
}

go();

API Reference

convertToPdf({ html, output, options })

Parameters

| Name | Type | Description | Required | |-----------|----------|----------------------------------------------------------------------------------------------|----------| | html | string | The HTML content to convert. | Yes | | output | string | Output file path for the generated PDF. | Yes | | options | object | PDF rendering options (see below). | No |


PDF Options (options)

These options are passed directly to Puppeteer's page.pdf():

| Option | Type | Default | Description | |-----------------------|----------|------------------------------------------------------------|-----------------------------------------------------------------------------| | format | string | "A4" | Paper format (A3, A4, A5, Letter, Legal) | | landscape | boolean | false | Orientation of the PDF | | printBackground | boolean | true | Include CSS backgrounds and images | | margin | object | {top:'20mm', bottom:'20mm', left:'15mm', right:'15mm'} | Page margins | | displayHeaderFooter | boolean | false | Enable header/footer rendering | | headerTemplate | string | - | HTML string for header (works only if displayHeaderFooter: true) | | footerTemplate | string | - | HTML string for footer | | scale | number | 1 | Scale of the webpage rendering (0.1–2) | | pageRanges | string | " " | e.g. "1-3" renders only specified pages | | width | string | - | Page width in px/mm/in (overrides format) | | height | string | - | Page height in px/mm/in | | preferCSSPageSize | boolean | false | Use CSS @page size if available |

Example options

options: {
  format: "A4",
  landscape: false,
  printBackground: true,
  margin: { top: "10mm", bottom: "10mm", left: "10mm", right: "10mm" },
  displayHeaderFooter: true,
  headerTemplate: "<div>Header</div>",
  footerTemplate: "<div>Page <span class='pageNumber'></span> / <span class='totalPages'></span></div>",
  scale: 1,
  pageRanges: "1-3",
  width: "210mm",
  height: "297mm",
  preferCSSPageSize: false
}

Advanced Usage

  • RTL Support: Use <html lang="ar" dir="rtl"> and set direction:rtl in your CSS.
  • Dynamic Content: Insert variables in your HTML before passing to convertToPdf.
  • Custom Fonts: Reference web fonts in your HTML <head>.

Output

The generated PDF will be saved at the path specified in the output parameter.

License

MIT

Author

AQ


Note:
If you need more examples or want to customize further, check the examples/ folder or open