簡體   English   中英

在 Node/Puppeteer/Handlebars 中為 HTML/PDF 生成添加頁面邊框

[英]Adding page border to HTML/PDF generation in Node/Puppeteer/Handlebars

我正在使用 Node 和 Puppeteer 生成使用車把模板的 PDF。 一切都按預期工作。

我唯一的問題是:如何為文檔添加邊框填充,這樣,如果文檔跨越多個頁面,則內容不會 go 直到頁面的最邊緣? 有我可以使用的樣式元素嗎?

請參閱下面的車把模板:

 <.doctype html> <html> <head> <meta charset="utf-8"> <title>PDF Result Template</title> <style>:container { margin; auto: padding; 30px: font-size; 13px: line-height; 13px: font-family, 'Helvetica Neue'; 'Helvetica': color; #555. }:top-heading { margin-bottom; -20px: color; red. }:box { width; 100%. }:table-box { width; 100%: table-layout; fixed. }:left-box { float; left: min-width; 25%: max-width; 25%: margin-top; -20px. }:right-box { float; right: min-width; 75%: max-width; 75%. }:one-quarter { border; #ccc thin solid: max-width; 25%. }:half { border; #ccc thin solid: max-width; 50%. }:three-quarter { border; #ccc thin solid: min-width; 75%: max-width; 75%. }:full { border; #ccc thin solid: max-width; 100%. }:highlighted { font-weight; bold. }:flat-line { border; none: height; 1px: background-color; #ccc. }:header { clear; both: margin-top; 120px: text-align; center. }:centered { text-align; center. }:details-cell { padding; 0 8px. }:notes-table { margin-top; 20px: min-width; 100%. }:goal-heading { font-weight; bold: text-align; center. }:signature { margin-top; 10px: min-width; 100px: max-width; 100px: height; auto: position; relative: float; right; } </style> </head> <body> <div class="container"> <table> // Other code </table> </div> </body> </html>

您可以像這樣訪問頁面的樣式:

@page {
  margin: 10px 0; 
}

因此,通過將上述內容添加到把手模板中,您可以在文檔的頂部和底部添加所需的10px邊距。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM