1

使用 IronPdf 生成 html 内容到 pdf,但是在 pdf 中生成 3 页页眉内容和页脚在单独的页面中,如何在单页洞内容中显示。

   var Renderer = new IronPdf.HtmlToPdf();
            //Renderer.PrintOptions.Header.DrawDividerLine = false;
            //Renderer.PrintOptions.Footer.DrawDividerLine = false;
            Renderer.PrintOptions.PaperSize = PdfPrintOptions.PdfPaperSize.A4;
            Renderer.PrintOptions.CssMediaType = PdfPrintOptions.PdfCssMediaType.Screen;
            Renderer.PrintOptions.PaperOrientation = PdfPrintOptions.PdfPaperOrientation.Portrait;
          //  Renderer.PrintOptions.MarginTop = 10;  //millimeters
           // Renderer.PrintOptions.MarginBottom = 10;
            Renderer.PrintOptions.Zoom = 125;
            //Renderer.PrintOptions.FirstPageNumber = 1;
            Renderer.PrintOptions.CreatePdfFormsFromHtml = true;
            Renderer.PrintOptions.FitToPaperWidth = true;
            Renderer.PrintOptions.InputEncoding = Encoding.UTF8;
            Renderer.PrintOptions.FitToPaperWidth = true;

pdf 将像这样生成:在此处输入图像描述

4

1 回答 1

0

添加页眉和页脚如下:

var PDF = Renderer.RenderHTMLFileAsPdf("HTML Body");
PDF.AddHTMLHeaders(new HtmlHeaderFooter() {
HtmlFragment = "HTMLHeader"
});

PDF.AddHTMLFooters(new HtmlHeaderFooter()
{
Height=20,
HtmlFragment = "HTML Footer"
});

https://ironpdf.com/object-reference/api/IronPdf.PdfDocument.html?q=AddHTMLHeaders#IronPdf_PdfDocument_AddHTMLHeaders_IronPdf_HtmlHeaderFooter_System_Double_System_Double_System_Double_System_Boolean_System_Collections_Generic_IEnumerable_System_Int32_ _

于 2021-05-19T06:17:28.790 回答