我有一個頁面需要打印為 PDF(另存為 PDF 或僅使用瀏覽器打印對話框),類似于:div { outline: red solid 1px;}body { margin-left: 30vw; margin-right: 30vw;}<div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div><br><div>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</div><br><div>該網站的內容較長,可以放在一個頁面中,因此當我嘗試打印時它會被切斷。我希望在每個段之前插入一個分頁符,如果它會在中間被剪切,那么段之間只有分頁符。我目前正在嘗試使用html2pdf.js避免所有分頁符模式:html2pdf().set({ pagebreak: { mode: ['avoid-all', 'css', 'legacy'] }});但這似乎沒有任何作用。我可以使用手動標記(將類添加html2pdf__page-break到應該在分頁符之前的元素中),但是我經常修改這個站點,而且我不想每次對站點進行更改時都必須返回元素更長或更短。
將頁面打印/保存為 PDF,但如果某個元素被截斷,則在它之前添加一個分頁符
Helenr
2021-08-20 18:31:14