亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

SelectPdf 僅在自定義頁面上顯示頁腳

SelectPdf 僅在自定義頁面上顯示頁腳

C#
拉莫斯之舞 2023-09-24 17:05:56
我正在使用SelectPDFHTML 模板將其轉換為 PDF。我遵循的設計要求僅在第一頁上顯示頁腳。該文檔不包括自定義頁面顯示。以前有人嘗試過這個嗎?
查看完整描述

1 回答

?
慕娘9325324

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();

我希望它能幫助你干杯


查看完整回答
反對 回復 2023-09-24
  • 1 回答
  • 0 關注
  • 168 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號