1.0.9 • Published 3 months ago

@hayzeddev/html-pdf-converter v1.0.9

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

HTML to PDF converter

This library converts HTML template to pdf. It works only on Node.js runtime for now. Subsequent releases would run on the client side (browser)

How to install

$ npm install --save @hayzeddev/html-pdf-converter

Usage

This works with both CJS and ESM.

import { generatePdf, pdfOptions } from '@hayzeddev/html-pdf-converter';
import { join } from 'path';

const options: pdfOptions = {
  path: join(__dirname, 'result.pdf'),
};

(async function () {
  const buffer: Buffer = await generatePdf(
    options,
    '<h3>Generated pdf from @hayzeddev/html-pdf-converter</h3>'
  );
  console.log(buffer);
})();
const generatePdf: (options: pdfOptions, html: string) => Promise<Buffer>;

Config

pdfOptions = {
    displayHeaderFooter?: boolean; //  Whether to show the header and footer. Defaults to `false`
 
    headerTemplate?: string; // Valid HTML template for the header
 
    footerTemplate?: string; // Valid HTML template for the footer
 
    printBackground?: boolean; // Set to `true` to print background graphics. Defaults to `false`
 
    landscape?: boolean; //  Whether to print in landscape orientation. Defaults to `false`

    format?: PaperFormatEnum; // The format of the pdf. It can be either of:  'Letter', 'Legal', 'Tabloid', 'Ledger', 'A0', 'A1', 'A2', 'A3', 'A4', 'A5','A6' Defaults to `letter`

    path?: string; // path where the file get written to in the disc. If not defined, pdf would not be saved to the disk
}
1.0.9

3 months ago

1.0.8

9 months ago

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago