html2pdf.js icon indicating copy to clipboard operation
html2pdf.js copied to clipboard

Line breaks don't work when generating Blob

Open vitorbraga opened this issue 3 years ago • 1 comments

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

vitorbraga avatar May 20 '22 15:05 vitorbraga

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

Shnrqpdr avatar Jul 18 '22 11:07 Shnrqpdr