[go: nahoru, domu]

node-hbs-to-pdf
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

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

Key type Description
template Buffer / string handlebar template (.hbs). It can be a Buffer or a string.
context object any data that you want to pass to handlebar template.
path (optional) string the path where you want to save the PDF file.
margin (optional) MarginObject the margin of the pdf
headerTemplate (optional) Buffer / string handlebar template for document header
footerTemplate (optional) Buffer / string handlebar template for document footer
puppeteer object puppeteer 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.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.1.12latest

Version History

VersionDownloads (Last 7 Days)Published
1.1.12
1.1.00
1.0.61
1.0.51
1.0.40
1.0.30
1.0.20
1.0.10
1.0.01

Package Sidebar

Install

npm i node-hbs-to-pdf

Weekly Downloads

4

Version

1.1.1

License

MIT

Unpacked Size

12.9 kB

Total Files

9

Last publish

Collaborators

  • dbernal