1.18.0 • Published 4 years ago

html-to-pdf-studio v1.18.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

html-to-pdf-studio

Converting HTML template to PDF files

Codacy Badge npm npm LICENSE Dependabot Status

System Requirements

Installing

  • yarn add html-to-pdf-studio

Usage

Compiling a handlebars HTML template

const fs = require("fs");
const path = require("path");
const { compileHTML, createPDF } = require("html-to-pdf-studio");

const cssPath = path.join(__dirname, "./example/templates/style.css");
const css = fs.readFileSync(cssPath, "utf8");

const htmlPath = path.join(__dirname, "./example/templates/index.html");
const html = fs.readFileSync(htmlPath, "utf8");

let data = require("./example/templates/data.json");
const dataBinding = Object.assign(data, { css });

const compiledHTML = compileHTML(html, dataBinding);

Create PDF file from final HTML compiled with handlebars previously demonstrated

const path = require("path");
const { createPDF } = require("html-to-pdf-studio");

const fileName = "invoide.pdf";
const outputPath = path.join(__dirname, "./example/output");

if (!fs.existsSync(outputPath)) fs.mkdirSync(outputPath);

const pdfOptions = {
  format: "A4",
  headerTemplate: "<p></p>",
  footerTemplate: "<p></p>",
  displayHeaderFooter: false,
  margin: {
    top: "40px",
    bottom: "100px",
  },
  printBackground: true,
  path: path.join(outputPath, fileName),
};

(async () => {
  await createPDF(compiledHTML, pdfOptions);
})();

Inspiration

tranchuong - html_to_pdf

License

Copylefted (c) 2020 Henrique Carvalho da Cruz Licensed under the MIT license.

1.18.0

4 years ago

1.17.0

4 years ago

1.16.0

4 years ago

1.15.0

5 years ago

1.14.0

5 years ago

1.13.0

5 years ago

1.12.0

5 years ago

1.11.0

5 years ago

1.10.0

5 years ago

1.9.0

5 years ago

1.8.0

5 years ago

1.7.0

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago