@asaje/html-to-pdf
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

html-to-pdf

HTML to PDF tool built with playwright

Installation

npm install @asaje/html-to-pdf

Usage

Generate pdf from html

import { Pdf } from '@asaje/html-to-pdf';

async function printPdf() {
  const pdf = new Pdf();
  await pdf.init();
  await pdf.printHtml({
    html: `<div><h1>Test</h1><p>Hello!</p></div>`,
    options: { path: 'sample.pdf' },
  });
  console.log('Pdf generated successfully');
}

printPdf();

printHtml() input object type

type PrintHtmlArgs = {
  html: string;
  context?: ContextOptions;
  options?: PrintOptions;
};

type ContextOptions = {
  timeout?: number;
  waitUntil?: 'load' | 'domcontentloaded' | 'networkidle' | 'commit';
};

type PrintOptions = {
  displayHeaderFooter?: boolean;
  footerTemplate?: string;
  format?: string;
  headerTemplate?: string;
  height?: string | number;
  landscape?: boolean;
  margin?: {
    top: string | number;
    right: string | number;
    bottom: string | number;
    left?: string | number;
  };
  outline?: boolean;
  pageRanges?: string;
  path?: string;
  preferCSSPageSize?: boolean;
  printBackground?: boolean;
  scale?: number;
  tagged?: boolean;
  width?: string | number;
};

type PageFormat =
  | 'Letter'
  | 'Legal'
  | 'Tabloid'
  | 'Ledger'
  | 'A0'
  | 'A1'
  | 'A2'
  | 'A3'
  | 'A4'
  | 'A5'
  | 'A6';

Package Sidebar

Install

npm i @asaje/html-to-pdf

Weekly Downloads

1

Version

1.0.4

License

ISC

Unpacked Size

7.14 kB

Total Files

7

Last publish

Collaborators

  • asaje379