1.0.6 • Published 3 months ago

node-hbs-to-pdf v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
3 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.0.6

3 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