1.1.2 • Published 10 months ago

node-hbs-to-pdf v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Handlebar template to PDF

This library converts hbs templates to pdf.

And that's all.

How to use

only call the "create" function

import { create, registerHelpers } from "node-hbs-to-pdf";
import myTemplate from "./myTemplate.hbs";

// create(props: CreateProps): Promise<Buffer>
const PDF = await create({
  template: myTemplate,
  context: {
    any: "context or data",
    key: "value",
  },
});
const headers = new Headers({ "Content-Type": "application/pdf" });
return new Response(body, { status: 200, headers });

// OR
await create({
  template: myTemplate,
  context: {
    any: "context or data",
    key: "value",
  },
  path: "/path/to/save/file.pdf",
});

Any problem importing the ".hbs" file? You can pass the file as ".txt" extension but having inside the handlebar template

import myTemplate from "./myTemplate.txt";

Props

KeytypeDescription
templateBuffer / stringhandlebar template (.hbs). It can be a Buffer or a string.
contextobjectany data that you want to pass to handlebar template.
path (optional)stringthe path where you want to save the PDF file.
margin (optional)MarginObjectthe margin of the pdf
headerTemplate (optional)Buffer / stringhandlebar template for document header
footerTemplate (optional)Buffer / stringhandlebar template for document footer
puppeteerobjectpuppeteer config, for now it only accepts noSandbox key (boolean)

MarginObject | Key | type | ------ | ------ | | top | string / number | | bottom | string / number | | left | string / number | | right | string / number |

How it works

This library uses the handlebar compiler to convert hbs template to html code and then, with puppeteer creates the pdf file.

1.1.2

10 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago