Socket
Book a DemoInstallSign in
Socket

html-to-document-adapter-pdf

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-to-document-adapter-pdf

PDF adapter for html-to-document-core — converts a DocumentElement tree into .pdf using the html2pdf.js library.

0.3.1
latest
Source
npmnpm
Version published
Weekly downloads
74
640%
Maintainers
1
Weekly downloads
 
Created
Source

html-to-document-adapter-pdf

PDF adapter for the html-to-document core library.

Installation

# Install this adapter (This assumes you have already installed
html-to-document or html-to-document-core) :

npm install html-to-document-adapter-pdf

If you're using the wrapper package (html-to-document), you'll still need to install this adapter separately.

For documentation on the wrapper:
https://www.npmjs.com/package/html-to-document

Usage

import { init } from 'html-to-document';
import { PdfAdapter } from 'html-to-document-adapter-pdf';

const converter = init({
  adapters: {
    register: [{ format: 'pdf', adapter: PdfAdapter }],
    defaultStyles: [
      {
        format: 'pdf',
        styles: {
          paragraph: { lineHeight: 1.5 },
          heading: { fontSize: '18px', fontWeight: 'bold' },
        },
      },
    ],
    styleMappings: [
      {
        format: 'pdf',
        handlers: {
          fontWeight: (v) => ({ bold: v === 'bold' }),
          textAlign: (v) => ({ align: v }),
        },
      },
    ],
  },
});

// Convert HTML string to PDF Blob or Buffer:
const htmlString = '<h1>Hello, PDF!</h1><p>This is a test.</p>';
const elements = await converter.parse(htmlString);
const pdfBlob = await converter.convert(elements, 'pdf');
// Use `pdfBlob` to download or save the file.

API

PdfAdapter

Adapter class implementing IDocumentConverter for PDF.

Constructor

new PdfAdapter(options: {
  styleMapper: StyleMapper;
  defaultStyles?: Record<string, any>;
});
  • styleMapper: a StyleMapper instance carrying style mappings.
  • defaultStyles: optional defaults for styling elements.

Methods

  • convert(elements: DocumentElement[]): Promise<Buffer | Blob>
    Converts parsed document elements into a PDF output.

Development

  • Clone the repo and run bun install at the root.
  • Build all workspaces: bun run build.
  • To test this adapter only:
    cd packages/adapters/pdf
    bun run test
    
  • Lint and format from root: bun run lint / bun run format.

License

ISC

Keywords

html-to-document

FAQs

Package last updated on 10 Aug 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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.