JSPM

@asaje/html-to-pdf

1.0.4
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 43
  • Score
    100M100P100Q62602F
  • License ISC

HTML to PDF tool built with playwright

Package Exports

  • @asaje/html-to-pdf
  • @asaje/html-to-pdf/dist/pdf.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@asaje/html-to-pdf) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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';