html-to-pdf-studio
Converting HTML template to PDF files
![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=henriquecarv/html-to-pdf-studio)
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.