const {PdfDocument} = require("@ironsoftware/ironpdf");
(async () => {
// Configure render options
const renderOptions = {
firstPageNumber: 1, // Use 2 if a cover page will be appended
// Build a footer using html to style the text
// mergeable fields are:
// {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
htmlFooter: {
maxHeight: 15, //millimeters
htmlFragment: "<center><i>{page} of {total-pages}<i></center>",
dividerLine: true,
},
// Build a header using an image asset
htmlHeader: {
maxHeight: 15, //millimeters
htmlFragment: "<img src='logo.png'>",
},
// Use sufficient MarginBottom to ensure that the HtmlFooter does not overlap with the main PDF page content.
margin: {
top: 25, // Create 25mm space for the header
bottom: 25, // Create 25mm space for the footer
},
};
})();
添加 HTML 頁眉和頁腳
配置渲染選項,以便在使用IronPDF (Iron Software的一個庫,允許高級 PDF 生成和操作)渲染 PDF 文件時包含 HTML 標題和頁腳。
使用 IronPDF 靈活的 PDF 渲染工具,透過分隔線、HTML 片段定義頁首內容,並指定頁首的最大高度。 同樣地,使用IronPDF提供的 htmlHeader 屬性定義頁尾內容。
請注意,頁首和頁尾的高度不會自動偵測,這表示它們可能會與主要 HTML 內容重疊。 調整頁邊距,確保頁首和頁尾位置適當。