eKoopmans / html2pdf.js

Client-side HTML-to-PDF rendering using pure JS.
MIT License
4.13k stars 1.39k forks source link

Line breaks don't work when generating Blob #552

Open vitorbraga opened 2 years ago

vitorbraga commented 2 years ago

Hi, I'm trying to generate a PDF with some line-breaks. I spread some <div class="html2pdf__page-break"/> across my HTML.

When I look into the preview (the window that appears when I try to generate the PDF), the line-breaks work fine.

But when I export it as a blob and save it on my server (S3), there are no line-breaks. Am I missing something here?

Here is my code:

const pdf = await html2pdf()
          .set({ pagebreak: { avoid: ['.avoid'] }, html2canvas: { scrollX: 0, scrollY: 0 }})
          .from(pdfContent)
          .toPdf()
          .get('pdf')
          .then((pdf) => pdf);
const preBlob = pdf.output('blob');

const formData = new FormData();
formData.append('report', preBlob, 'my-file.pdf');

Thanks

Shnrqpdr commented 2 years ago

Hi. I worked in a similar problem 1 month ago and remove class and set the all custom styles on " style=" " " directive works for me.

Try this one