jsPDF
jsPDF copied to clipboard
The page-break feature is broken, right now it's not possible to prevent a div from being split
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.
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`)
Thanks @AutismPatient this works for my use case where I fetch different html strings for each page and want them rendered as separate pages
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.