Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 1.22 KB

README.md

File metadata and controls

41 lines (31 loc) · 1.22 KB

micro-pdf

Node Micro-service to convert HTML into PDFs 📄

Uses Puppeteer to render the page with a real chrome headless browser and prints it to PDF. Uses real chrome browser so what you see on your browser is what you get. This makes development much easier.

Deploy

Server Side

Can be hosted on any provider with node runtime support.

npm install
npm run start

Client Side

Make a post request with { html : YOUR_HTML } and the response will be the PDF document

Example:

fetch("http://localhost:3000", {
  method: "POST",
  body: JSON.stringify({
    html: "<h1>Hello I am a PDF</h1>",
  }),
})
  .then((response) => response.blob())
  .then((blob) => {
    var url = window.URL.createObjectURL(blob);
    var a = document.createElement("a");
    a.href = url;
    a.download = "example.pdf"; // You can set the name programmatically
    document.body.appendChild(a); // we need to append the element to the dom -> otherwise it will not work in firefox
    a.click();
    a.remove(); //afterwards we remove the element
  });