SelectPdf 仅在自定义页面上显示页脚

我正在使用SelectPDFHTML 模板将其转换为 PDF。我遵循的设计要求仅在第一页上显示页脚。

文档不包括自定义页面显示。

以前有人尝试过这个吗?


拉莫斯之舞
浏览 116回答 1
1回答

慕娘9325324

正如您所看到的文档,您可以创建自定义 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);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; footerHtml.AutoFitHeight = HtmlToPdfPageFitMode.AutoFit;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; converter.Footer.Add(footerHtml);更新:这段代码从 URL 创建一个新的 pdf,并为第一页添加自定义页脚。PdfDocument doc = converter.ConvertUrl(@"https://en.wikipedia.org/wiki/Chernobyl_disaster");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PdfPage page = doc.Pages[0];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PdfTemplate customFooter = doc.AddTemplate(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; page.PageSize.Width, 20);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PdfHtmlElement customHtml = new PdfHtmlElement(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "<div><b>This is the custom footer that will " +&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "appear only on page 1!</b></div>",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string.Empty);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; customFooter.Add(customHtml);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; page.CustomFooter = customFooter;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.Save("Test.pdf");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.Close();我希望它能帮助你干杯
打开App,查看更多内容
随时随地看视频慕课网APP