html2pdf.js 解決分頁內容截斷問題


基於html2pdf.js將html頁面導出為pdf

分頁內容截斷問題:

如果你用的是Vue,可以采用 https://github.com/kempsteven/vue-html2pdf 這個開源庫已經解決了該問題,通過計算的方式。
實現的計算原理:

偽代碼:
累計每個子元素的高度如果大於紙張高度(如 A4 ),
countChildrenHeight = 0
if (countChildrenHeight > paperHeight) {
// 就在該子元素之前插入分頁符(Page-Break)
// parentElement.insertBefore(pageBreakElement, childrenElement);
countChildrenHeight = 0
} else {
countChildrenHeight += childrenHeight;
}

具體實現可以參考 vue-html2pdf:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM