jsPDF icon indicating copy to clipboard operation
jsPDF copied to clipboard

The page-break feature is broken, right now it's not possible to prevent a div from being split

Open clcoco opened this issue 1 year ago • 2 comments

I have read and understood the contribution guidelines.

This example says that you can use CSS classes to prevent HTML elements from breaking, but right now the feature is broken since it doesn't nothing: even the example doesn't work.

clcoco avatar Nov 27 '23 12:11 clcoco

Analogous

html

<div class="export_content">
  <p>test</p>
</div>
<div class="export_content">
  <p>test1</p>
</div>

typescript

const options: jsPDFOptions = {
        orientation: 'landscape'
}

const htmlOptions: HTMLOptions = {
        jsPDF: doc,
        autoPaging: false,
        windowWidth: pdfWidth.value, //target width in the PDF document
        width: 297,
        html2canvas: {
          useCORS: true,
          allowTaint: false,
        },
        x: 0,
        y: 0,
      }

let doc = new jsPDF(options)

const docDiv = document.getElementsByClassName("export_content") as HTMLCollectionOf<HTMLDivElement>

await doc.html(docDiv[0], htmlOptions)


      for (let i = 1; i < docDiv.length; i++) {
        doc.addPage()
        await doc.html(docDiv[i], htmlOptions)
      }

      // Save the PDF
      doc.save(`test.pdf`)

AutismPatient avatar Dec 01 '23 03:12 AutismPatient

Thanks @AutismPatient this works for my use case where I fetch different html strings for each page and want them rendered as separate pages

Amar-Gill avatar Jan 31 '24 05:01 Amar-Gill

This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.

github-actions[bot] avatar May 01 '24 01:05 github-actions[bot]