在Migradoc的最后一页添加页脚

问题描述 投票:0回答:2

我需要在MigraDoc上添加一个页脚。以下代码将页脚添加到所有页面。

该页面有一个标题,需要在每个页面上显示。

 Document document = new Document();
 PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(false);
 Section HeaderSection = document.AddSection();
 HeaderSection.PageSetup.DifferentFirstPageHeaderFooter = false;

 MigraDoc.DocumentObjectModel.Shapes.Image image = HeaderSection.Headers.Primary.AddImage("../images/logo.jpg");
 image.Height = new Unit(65);
 image.Width = new Unit(150);
 image.LockAspectRatio = false;
 image.RelativeVertical = RelativeVertical.Line;
 image.RelativeHorizontal = RelativeHorizontal.Margin;

 Paragraph ParaHead1 = HeaderSection.AddParagraph();
 Parahead1.AddFormattedText("..dfg");
 Table table = HeaderSection.Footers.Primary.AddTable();
 table.Borders.Width = 0;

 Column column = table.AddColumn();
 column.Width =Unit.FromPoint(300);
 column.Format.Alignment = ParagraphAlignment.Left;
 Column column1 = table.AddColumn();
 column1.Width = Unit.FromPoint(200);
 column1.Format.Alignment = ParagraphAlignment.Left;
 Row row = table.AddRow();

 Cell cell = row.Cells[0];
 cell.AddParagraph("Regards,");
 cell = row.Cells[1];
 Paragraph para1 = cell.AddParagraph();
 para1.AddFormattedText("Support Team");

我需要页脚表只出现在最后一页。

我不希望添加最后一个段落作为页脚作为页脚,因为这将导致页脚出现只显示文本。

页面上的内容是动态的。

pdfsharp migradoc
2个回答
0
投票

您不能仅在最后一页使用MigraDoc页脚作为页脚。

要实现此效果,您必须将文本添加到主体 - 或稍后使用PDFsharp绘制页脚。

您可以使用TextFrame将页脚放在固定位置,但您必须注意TextFrame不会与其他主体内容重叠。

要回答评论中的问题:

  • 要将“页脚”直接放在内容下方,只需将其以您喜欢的任何形式添加到主体(表格,段落......)
  • 要将页脚放在绝对位置(例如使用TextFrame):我建议在主体文本中添加一个空的虚拟段落(如果需要),以确保页脚不与主体重叠;虚拟段落的高度将是与文档主体区域重叠的页脚高度

0
投票

我使用的方法是在Section中为PageSetup添加一个标志。该标志告诉引擎使用LastPageHeader和LastPageFooter关键字指定的页面替换最后一页页眉和页脚。

这是支持最后一页页眉和页脚的部分示例(它使用特殊的Migradoc / xml语法,但它也支持原始的mddl):

<Section>
      <Attributes>
          <PageSetup PageHeight="29.7cm" PageWidth="21cm" Orientation="Portrait" DifferentLastPageHeaderFooter="true"/>
      </Attributes>
      <LastPageHeader>
      ....
      </LastPageHeader>
      <LastPageFooter>
      ....
      </LastPageFooter>
  </Section>

支持此功能的分支可在此处获得:https://github.com/emazv72/MigraDoc 请注意,LastPageHeader和LastPageFooter仅适用于PDF,而不适用于RTF。

© www.soinside.com 2019 - 2024. All rights reserved.