html2pdf-ts
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

HTML2PDF-TS

NPM badges

NPM html2pdf-ts package npm downloads npm downloads

Description

Simple lib to convert HTML to PDF, using puppeteer.

This package have the following features:

  • [x] Create the PDF file and save.
  • [x] Create the PDF buffer and return.
  • [x] Create the PDF file with password and return.
  • [x] Create the PDF buffer with password and return.

Install

npm  i  html2pdf-ts
yarn add html2pdf-ts

Example

To execute an example, just run:

npm  run  start

or

yarn  start

Using the package:

import { promises  as  fs } from  'fs';
import { html2pdf } from  '../src/index';
import { HTML2PDFOptions } from  '../src/types';

const  example = async () => {
	const  html = await  fs.readFile('./example/page.html', 'utf-8');
	const  options: HTML2PDFOptions = {
		format:  'A4',
		filePath:  './example/lotr.pdf',
		landscape:  false,
		protect: {
			password:  '1234',
		},
		resolution: {
			height:  1920,
			width:  1080,
		},
	};

	await  html2pdf.createPDF(html, options);

	console.log('PDF Generated...');
};

example();

The example above create a PDF with password and save it.

To create the PDF without password, just remove the param protect from options, and to get only the buffer, remove the filePath.

In addition, you can read a html file and pass the content to create the PDF, or just pass a pure HTML as param.

Tests

To execute tests run:

yarn test

With coverage:

yarn test:cov

License

Released under the MIT License.

Package Sidebar

Install

npm i html2pdf-ts

Weekly Downloads

404

Version

1.1.1

License

ISC

Unpacked Size

14.2 kB

Total Files

14

Last publish

Collaborators

  • vitorric