alvarcarto / url-to-pdf-api

Web page PDF/PNG rendering done right. Self-hosted service for rendering receipts, invoices, or any content.
MIT License
7.03k stars 779 forks source link

how to generate a PDF with automatic height? #87

Open ddahan opened 6 years ago

ddahan commented 6 years ago

I use this Puppeteer microservice to generate receipts in PDF. For each receipt, width is always the same, but height changes, according to the article count in the order.

For now, I'm using the article count to approximate the required height for my receipt. It kind of works, but it's not perfect and is a dirty way to do. Is there way to tell Puppeteer API : "Please automatically find the right PDF height, according to the HTML body height, in order to generate a perfectly sized PDF" ?

kimmobrunfeldt commented 5 years ago

This is a great question, but unfortunately I don't know how to achieve it with Chrome rendering. You could look into issues in https://github.com/GoogleChrome/puppeteer if there are similar questions.

neerajtomar98 commented 4 years ago

I use this Puppeteer microservice to generate receipts in PDF. For each receipt, width is always the same, but height changes, according to the article count in the order.

For now, I'm using the article count to approximate the required height for my receipt. It kind of works, but it's not perfect and is a dirty way to do. Is there way to tell Puppeteer API : "Please automatically find the right PDF height, according to the HTML body height, in order to generate a perfectly sized PDF" ?

@ddahan can you please share how exactly you are solving this issue. Iam facing similar issue.

kimmobrunfeldt commented 4 years ago

I tried to solve this in this branch https://github.com/alvarcarto/url-to-pdf-api/pull/119 but without success.