首页 文章

MigraDoc页眉和页脚

提问于
浏览
4

我已经尝试了 DifferentFirstPageHeaderFooter 但是它设置了一些组合,以及添加页眉和页脚的正确位置,但我没有根据MigraDoc发票样本编写代码 . 封面是一个部分,然后文档的其余部分是一个带分页符的部分 . 也许我需要将其分成每页一节?谢谢你的任何提示 .

编辑

我得到了 Headers 显示,但似乎有一个更好的方法来做它比我正在做的 . 页脚根本没有显示出来 . 这是我添加它们的地方:

Document document = new Document();
Section section = document.AddSection();

section.PageSetup.DifferentFirstPageHeaderFooter = true;        

Paragraph paragraph = section.Footers.Primary.AddParagraph();
paragraph.AddFormattedText(ReportName, TextFormat.Bold);
paragraph.AddText("\nCreated on ");
paragraph.AddFormattedText(CreateDate, TextFormat.Bold);
paragraph.AddFormattedText("\n" + Properties.Length, TextFormat.Bold);
paragraph.AddText(" Records");
paragraph.AddFormattedText("\n" + TurnoverPercent, TextFormat.Bold);
paragraph.AddText(" Turnover Rate");
paragraph.Format.Font.Size = 10;
paragraph.Format.Alignment = ParagraphAlignment.Center;

// Later, in a different method...
Section section = document.AddSection();

    // Header image
    Image image = section.Headers.Primary.AddImage(filename);
    image.Height = "2.5cm";
    image.LockAspectRatio = true;
    image.RelativeVertical = RelativeVertical.Line;
    image.RelativeHorizontal = RelativeHorizontal.Margin;
    image.Top = ShapePosition.Top;
    image.Left = ShapePosition.Right;
    image.WrapFormat.Style = WrapStyle.Through;

    image = section.Headers.FirstPage.AddImage(filename);
    image.Height = "2.5cm";
    image.LockAspectRatio = true;
    image.RelativeVertical = RelativeVertical.Line;
    image.RelativeHorizontal = RelativeHorizontal.Margin;
    image.Top = ShapePosition.Top;
    image.Left = ShapePosition.Right;
    image.WrapFormat.Style = WrapStyle.Through;

我尝试将页脚段添加到Primary和FirstPage,它似乎没有什么区别 . DifferentFirstPageHeaderFooter 仅适用于部分,权利,而不是整个文件?

2 回答

  • 2

    好吧,我已经弄清楚了 . 似乎 DifferentFirstPageHeaderFooter 不仅适用于您设置的部分,而是适用于每个部分 . 一旦我在每个部分适当地设置它,我的问题都得到了解决,页眉和页脚出现在我想要的地方 . 这是更新的代码 .

    Section section = document.AddSection();
    
    section.PageSetup.DifferentFirstPageHeaderFooter = true;        
    
    Paragraph paragraph = section.Footers.FirstPage.AddParagraph();
    paragraph.AddFormattedText(ReportName, TextFormat.Bold);
    paragraph.AddText("\nCreated on ");
    paragraph.AddFormattedText(CreateDate, TextFormat.Bold);
    paragraph.AddFormattedText("\n" + Properties.Length, TextFormat.Bold);
    paragraph.AddText(" Records");
    paragraph.AddFormattedText("\n" + TurnoverPercent, TextFormat.Bold);
    paragraph.AddText(" Turnover Rate");
    paragraph.Format.Font.Size = 10;
    paragraph.Format.Alignment = ParagraphAlignment.Center;
    
    // Later, in a different method...
    Section section = document.AddSection();
    
    // Need to do this even though we've never set this field on this section
    section.PageSetup.DifferentFirstPageHeaderFooter = false;
    
        // Header image
        Image image = section.Headers.Primary.AddImage(filename);
        image.Height = "2.5cm";
        image.LockAspectRatio = true;
        image.RelativeVertical = RelativeVertical.Line;
        image.RelativeHorizontal = RelativeHorizontal.Margin;
        image.Top = ShapePosition.Top;
        image.Left = ShapePosition.Right;
        image.WrapFormat.Style = WrapStyle.Through;
    
  • 5

    DifferentFirstPageHeaderFooter 就是你所需要的 .

    可能你的代码不正确 - 是的,我们希望看到一些代码 . 如果没有看到您的代码,我们如何帮助您?

    每个部分有一页的许多部分都可以使用 - 但这并不是MigraDoc的使用方式 .

相关问题