Skip to content

vigzmv/micro-pdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
  });

About

HTML in PDF out. Node Micro-service to convert HTML into PDFs 📄

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published