IRONSOFTWAREHOME

How to Create PDF Files in Node.js

Curtis Chau
Curtis Chau
Updated: July 29, 2026

Creating PDF files programmatically in Node.js requires a library that handles HTML rendering accurately, supports modern CSS, and integrates cleanly with Node's async patterns. IronPDF uses a Chromium-based rendering engine to convert HTML content into PDFs that match Chrome's print output, supporting full CSS, inline JavaScript, and responsive layouts out of the box.

This guide covers the complete workflow: installation, generating PDFs from HTML strings, HTML files, and URLs, configuring output options, and applying enterprise features like headers, footers, digital signatures, and encryption.

Quickstart: Create a PDF in Node.js
  1. Install IronPDF via npm: npm install @ironsoftware/ironpdf
  2. Import PdfDocument from @ironsoftware/ironpdf
  3. Call PdfDocument.fromHtml() with your HTML content
  4. Call .saveAs() to write the PDF file to disk
import { PdfDocument } from "@ironsoftware/ironpdf";

const pdf = await PdfDocument.fromHtml("<h1>Hello, PDF!</h1><p>Generated with IronPDF.</p>");
await pdf.saveAs("output.pdf");
JavaScript

Configure IronPdfEngine for your platform before running in production. See the IronPdfEngine setup guide for Windows, Linux, macOS, and Docker instructions.

How Do I Install IronPDF for Node.js?

Install the @ironsoftware/ironpdf package using npm. The package works with Node.js 12.0 or higher and supports both ESM and CommonJS module formats.

npm install @ironsoftware/ironpdf
SHELL

IronPDF for Node.js depends on the IronPDF Engine binary, which handles the underlying Chromium-based rendering. The engine downloads automatically on first run, but you can pre-install the platform-specific package to avoid runtime downloads. This is useful in restricted network environments or Docker-based CI pipelines:

IronPDF Engine platform packages for pre-installation in offline or restricted environments

PlatformPackage
Windows x64@ironsoftware/ironpdf-engine-windows-x64
Linux x64@ironsoftware/ironpdf-engine-linux-x64
macOS x64@ironsoftware/ironpdf-engine-macos-x64
macOS ARM@ironsoftware/ironpdf-engine-macos-arm64
Please note: A valid license key removes the watermark from generated PDFs. Apply it before your first PdfDocument call by setting IronPdfGlobalConfig.setConfig({ licenseKey: "YOUR-KEY" }). Follow the full license key setup instructions.

What Are the System Requirements for IronPDF?

IronPDF for Node.js runs on Node.js 12.0 or higher on Windows, Linux, macOS, and Docker environments. The library supports both x64 and ARM64 architectures, making it suitable for local development and containerized deployments. For cloud environments, IronPDF also supports connecting to a remote IronPDF Engine instead of running the engine locally.


How Do I Create a PDF from HTML in Node.js?

Use PdfDocument.fromHtml() to generate a PDF from an HTML string. The method accepts any valid HTML, including inline <style> blocks, external fonts loaded via CDN, and layout systems like CSS Grid or Flexbox. The Chromium renderer resolves all resources before generating the PDF.

import { PdfDocument } from "@ironsoftware/ironpdf";

const htmlContent = `
  <!DOCTYPE html>
  <html>
  <head>
    <style>
      body { font-family: Arial, sans-serif; margin: 0; padding: 0; }
      .header { background: #2b4c8c; color: white; padding: 24px 32px; }
      .header h1 { margin: 0; font-size: 22px; }
      .body { padding: 32px; }
      table { width: 100%; border-collapse: collapse; margin-top: 16px; }
      th { background: #f0f4fb; text-align: left; padding: 8px 12px; }
      td { padding: 8px 12px; border-bottom: 1px solid #e0e0e0; }
    </style>
  </head>
  <body>
    <div class="header"><h1>Invoice #INV-2025-0042</h1></div>
    <div class="body">
      <p>Date: ${new Date().toLocaleDateString()}</p>
      <table>
        <tr><th>Item</th><th>Qty</th><th>Unit Price</th><th>Total</th></tr>
        <tr><td>IronPDF Enterprise License</td><td>1</td><td>$499.00</td><td>$499.00</td></tr>
        <tr><td>Priority Support (1 year)</td><td>1</td><td>$199.00</td><td>$199.00</td></tr>
      </table>
      <p style="text-align:right; margin-top:16px;"><strong>Total: $698.00</strong></p>
    </div>
  </body>
  </html>`;

// Generate the PDF from the HTML string
const pdf = await PdfDocument.fromHtml(htmlContent);
await pdf.saveAs("invoice.pdf");
JavaScript

PdfDocument.fromHtml() returns a PdfDocument instance. Call saveAs() with your desired output path to write the file. The method is asynchronous, so use await or chain a .then() handler. The Chromium engine handles font loading, external stylesheets, and asset resolution before capturing the output. For more patterns, see the HTML string to PDF example.

How Do I Create a PDF from an HTML File?

Load an existing .html file from disk using PdfDocument.fromFile(). This approach works well for templated documents where the HTML is maintained separately from the application logic.

import { PdfDocument } from "@ironsoftware/ironpdf";

// Load an HTML file and render it as a PDF
const pdf = await PdfDocument.fromFile("./templates/report-template.html");
await pdf.saveAs("./output/report.pdf");
JavaScript

The renderer resolves relative asset paths from the HTML file's directory, so local CSS and image references work without additional configuration. See the HTML file to PDF example for additional options, including how to override the base URL for asset resolution.

How Do I Generate a PDF from a URL?

Use PdfDocument.fromUrl() to render a live web page as a PDF. The renderer loads the page as a full browser session, executing JavaScript, applying CSS, and waiting for dynamic content before capturing the output.

import { PdfDocument } from "@ironsoftware/ironpdf";

// Render a live webpage to PDF
const pdf = await PdfDocument.fromUrl("https://ironpdf.com/nodejs/");
await pdf.saveAs("ironpdf-homepage.pdf");
JavaScript

For pages that load content asynchronously via JavaScript, pair this with a renderDelay option (in milliseconds) to allow additional time before capture. The URL to PDF example demonstrates delay configuration and authentication headers.


How Do I Configure PDF Output Settings?

Pass a configuration object as the second argument to PdfDocument.fromHtml(), PdfDocument.fromFile(), or PdfDocument.fromUrl(). The configuration object accepts paper size, margins, orientation, and rendering options.

import { PdfDocument, PdfPaperSize } from "@ironsoftware/ironpdf";

const config = {
    paperSize: PdfPaperSize.A4,
    marginTop: 25,
    marginBottom: 25,
    marginLeft: 20,
    marginRight: 20,
    landscape: false,
    printBackground: true,
};

const pdf = await PdfDocument.fromHtml("<h1>Configured PDF</h1>", config);
await pdf.saveAs("configured-output.pdf");
JavaScript

Key configuration options include:

  • paperSize: accepts PdfPaperSize enum values (A4, Letter, Legal, and custom sizes)
  • landscape: set true for landscape page orientation
  • printBackground: include CSS background colors and images
  • marginTop/Bottom/Left/Right: page margins in millimeters
  • renderDelay: milliseconds to wait before capture for JavaScript-heavy pages

How Do I Add Headers and Footers to a PDF?

Add headers and footers by providing htmlHeader and htmlFooter properties in the configuration object. Both accept full HTML strings, enabling styled content with page numbers, dates, and dynamic text.

import { PdfDocument } from "@ironsoftware/ironpdf";

const config = {
    htmlHeader: {
        htmlFragment: "<div style='text-align:center; font-size:12px; color:#666;'>Quarterly Report - Confidential</div>",
        dividerLine: true,
    },
    htmlFooter: {
        htmlFragment: "<div style='text-align:right; font-size:10px;'>Page {page} of {total-pages}</div>",
        dividerLine: true,
    },
};

const pdf = await PdfDocument.fromHtml("<h1>Q3 Financial Summary</h1><p>See attached tables.</p>", config);
await pdf.saveAs("report-with-headers.pdf");
JavaScript

Use {page} and {total-pages} tokens in the footer HTML; IronPDF substitutes the correct values at render time. For more header and footer patterns, including HTML headers and footers and advanced header techniques, see the linked examples.


How Do I Add Security and Metadata to a PDF?

Apply password protection and encryption to a generated PDF using the PdfDocument security methods. The library supports both owner and user passwords, with granular permission controls for printing, copying, and editing.

import { PdfDocument } from "@ironsoftware/ironpdf";

const pdf = await PdfDocument.fromHtml("<h1>Confidential Document</h1>");

// Apply password protection with granular permissions
await pdf.securePdf({
    userPassword: "view-password",
    ownerPassword: "admin-password",
    allowUserAnnotations: false,
    allowUserPrinting: true,
    allowUserCopyPasteContent: false,
});

await pdf.saveAs("secured-document.pdf");
JavaScript

Encryption and decryption use 128-bit RC4 encryption by default when passwords are applied, with AES-128 and AES-256 available as selectable options. For document authentication workflows, IronPDF also supports digital signatures using X.509 certificates.

Tips: For documents that require long-term archival compliance, use PdfDocument.fromHtml() followed by the PDF/A conversion method. IronPDF supports PDF/A compliance and PDF/UA accessibility standards.

How Do I Merge and Manipulate Existing PDFs?

PdfDocument provides methods for merging, splitting, and modifying existing PDF files. Load an existing PDF with PdfDocument.fromFile() and use the manipulation methods to add or remove pages, stamp content, or replace text.

import { PdfDocument } from "@ironsoftware/ironpdf";

// Merge two PDF files into one
const merged = await PdfDocument.mergePdf([
    await PdfDocument.fromFile("./report-part1.pdf"),
    await PdfDocument.fromFile("./report-part2.pdf"),
]);

await merged.saveAs("./complete-report.pdf");
JavaScript

PdfDocument.mergePdf() accepts an array of PdfDocument instances and returns a single merged document. Page order follows the array order, so the output preserves the sequence of the input files.

Other common manipulation operations:

For high-volume scenarios, multi-threaded PDF generation lets you process multiple documents in parallel. PDF compression reduces file sizes for storage and transmission.


How Do I Generate PDFs for Complex Content Like Charts and Angular Pages?

IronPDF renders pages using a full Chromium browser session, which means JavaScript libraries that produce charts, graphs, or data visualizations render correctly, including JavaScript chart libraries. Single-page applications built with frameworks like Angular also convert cleanly using the Angular to PDF example.

For Unicode-heavy documents or multi-language output, IronPDF handles Unicode and international character sets without additional configuration. The Google Fonts integration example shows how to load web fonts in the rendered HTML for consistent typography in the output PDF.

Please note: IronPDF's Chromium renderer executes JavaScript before capturing the PDF. If your chart library or SPA requires additional time to render data after the DOM loads, set renderDelay in milliseconds to give the page time to fully render.

What Are the Next Steps for Creating PDFs in Node.js?

This guide covered the core IronPDF workflow: installing the library, generating PDFs from HTML strings, files, and URLs, configuring output settings, adding headers and footers, applying security, and manipulating existing PDFs.

To continue, try the complete HTML to PDF tutorial for a deeper walkthrough of rendering options, or browse the API Reference for the full list of PdfDocument methods and configuration properties.

Start your free trial to generate PDFs without watermarks, or view licensing options for production deployments.

Frequently Asked Questions

How do I create a PDF from HTML in Node.js using IronPDF?

To create a PDF from HTML in Node.js using IronPDF, you can use the `PdfDocument.fromHtml()` method. This method accepts a valid HTML string and returns a PdfDocument object, which you can then save using `saveAs()`. The Chromium renderer ensures all resources like CSS and external fonts are resolved before generating the PDF.

How can I install IronPDF for Node.js?

You can install IronPDF for Node.js via npm by running the command `npm install @ironsoftware/ironpdf`. This package supports Node.js 12.0 or higher and provides both ESM and CommonJS module formats.

What configuration options does IronPDF offer for PDF output?

IronPDF allows you to configure various output settings including paper size, margins, orientation, and rendering options by passing a configuration object to `PdfDocument.fromHtml()`, `fromFile()`, or `fromUrl()`. This can include settings like `paperSize`, `landscape`, and `printBackground`.

Can I add headers and footers when creating PDFs with IronPDF?

Yes, IronPDF allows you to add headers and footers to your PDFs by including `htmlHeader` and `htmlFooter` properties in the configuration object. These properties accept full HTML strings, which can contain styled content and use tokens like `{page}` for dynamic page numbers.

How do I secure a PDF using IronPDF?

You can secure a PDF with IronPDF by using the `securePdf()` method on a `PdfDocument` instance. This allows you to add user and owner passwords, as well as set permissions like allowing or disallowing printing and copying.

What are some methods for manipulating existing PDFs with IronPDF?

IronPDF provides various methods to manipulate existing PDFs, including `mergePdf()` for combining documents, `removePages()` to delete specific pages, and methods to stamp content or replace text.

Can I use IronPDF to create PDFs from live web pages?

Yes, IronPDF can render live web pages to PDFs using `PdfDocument.fromUrl()`. The method loads the page as a full browser session, executing JavaScript and applying CSS before generating the PDF. You can also configure a `renderDelay` to ensure all dynamic content is captured.

Is it possible to apply digital signatures to PDFs with IronPDF?

Yes, IronPDF supports applying digital signatures to PDFs using X.509 certificates. This feature is useful for document authentication and secure workflows.

How does IronPDF handle complex content like charts in PDFs?

IronPDF uses a full Chromium browser session to render pages, which means JavaScript chart libraries and frameworks like Angular are fully supported. This allows charts, graphs, and other complex visualizations to render correctly in the output PDFs.

What are the system requirements for using IronPDF on Node.js?

IronPDF requires Node.js 12.0 or higher and runs on Windows, Linux, macOS, and Docker environments. It supports both x64 and ARM64 architectures, making it suitable for various deployment scenarios including local development and cloud environments.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Version:2026.8just released

Get your free 30-day Trial Key instantly.
No credit card or account creation required
Node.js Module Download for PDF
Install with npm

Version: 2026.8

  1. Download and install Node.js 12+.
  2. Execute the above command in the terminal.

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required
Node.js Module Download for PDF
Install with npm

Version: 2026.8

  1. Download and install Node.js 12+.
  2. Execute the above command in the terminal.

Licenses from $999