1 回答

TA貢獻1783條經驗 獲得超4個贊
正如您所看到的文檔,您可以創建自定義 HTML 文檔,其名稱為 footer.html。該文檔將包含您的自定義頁腳。
這就是初始化。
string footerUrl = Server.MapPath("~/files/footer.html");
之后,您必須初始化轉換器對象并設置它。
HtmlToPdf converter = new HtmlToPdf();
converter.Options.DisplayFooter = true;
converter.Footer.DisplayOnFirstPage = true;
PdfHtmlSection footerHtml = new PdfHtmlSection(footerUrl);
footerHtml.AutoFitHeight = HtmlToPdfPageFitMode.AutoFit;
converter.Footer.Add(footerHtml);
更新:
這段代碼從 URL 創建一個新的 pdf,并為第一頁添加自定義頁腳。
PdfDocument doc = converter.ConvertUrl(@"https://en.wikipedia.org/wiki/Chernobyl_disaster");
PdfPage page = doc.Pages[0];
PdfTemplate customFooter = doc.AddTemplate(
page.PageSize.Width, 20);
PdfHtmlElement customHtml = new PdfHtmlElement(
"<div><b>This is the custom footer that will " +
"appear only on page 1!</b></div>",
string.Empty);
customFooter.Add(customHtml);
page.CustomFooter = customFooter;
doc.Save("Test.pdf");
doc.Close();
我希望它能幫助你干杯
- 1 回答
- 0 關注
- 168 瀏覽
添加回答
舉報