Search code examples
migradoc

MigraDoc - Put TextFrame on Dynamically Generated Pages/Sections


The red type paragraph generates multiple pages. Is it possible to put a TextFrame (that is not in a header or footer) to show up on each dynamically generated page/section in MigraDoc without putting it in a header or footer?

enter image description here

public static Document CreateWorkOrderPDF2(Document document, string filename, string WorkOrderHeader, string myMessage)
    {
        Section section = document.AddSection();
        section.PageSetup.PageFormat = PageFormat.Letter;

        section.PageSetup.StartingNumber = 1;

        section.PageSetup.LeftMargin = 40;
        //Sets the height of the top margin
        section.PageSetup.TopMargin = 100;
        section.PageSetup.RightMargin = 40;
        section.PageSetup.BottomMargin = 40;

        //HeaderFooter
        HeaderFooter header = section.Headers.Primary;
        header.Format.Font.Size = 16;
        header.Format.Font.Color = Colors.DarkBlue;

        //Image
        MigraDoc.DocumentObjectModel.Shapes.Image headerImage = header.AddImage("../../Fonts/castorgate.regular.png");
        headerImage.Width = "2cm";

        Paragraph headerParagraph = header.AddParagraph(WorkOrderHeader);
        headerParagraph.Format.Font.Name = "Consolas";

         //Vertical Text
        TextFrame WorkOrderVerticalTextFrame = section.AddTextFrame();
        WorkOrderVerticalTextFrame.Orientation = TextOrientation.Downward;
        //moves text to the right
        WorkOrderVerticalTextFrame.Left = 550;
        WorkOrderVerticalTextFrame.Width = 10;
        WorkOrderVerticalTextFrame.Top = 0;
        WorkOrderVerticalTextFrame.Height = 150;
        WorkOrderVerticalTextFrame.WrapFormat.Style = WrapStyle.Through;

        Paragraph WorkOrderVerticalParagraph = WorkOrderVerticalTextFrame.AddParagraph();
        WorkOrderVerticalParagraph.Format.Alignment = ParagraphAlignment.Left;
        WorkOrderVerticalParagraph.Format.Font.Name = "Consolas";
        WorkOrderVerticalParagraph.Format.Font.Size = 8;
        WorkOrderVerticalParagraph.AddText(WorkOrderHeader);
        //WorkOrderVerticalParagraph.Format.Borders.Width = .5;


        //BODY PARAGRAPH
        Paragraph EstRecordsParagraph = section.AddParagraph(myMessage);
        EstRecordsParagraph.Format.Font.Size = 10;
        EstRecordsParagraph.Format.Font.Color = Colors.DarkRed;
        EstRecordsParagraph.Format.Borders.Width = .5;
        EstRecordsParagraph.Format.RightIndent = 0;

        Paragraph renderDate = section.AddParagraph();
        renderDate = section.AddParagraph("Work Order Generated: ");
        renderDate.AddDateField();

        return document;
    }

Solution

  • No.

    You can add a TextFrame to the section; then it will appear once in that section.

    You can add a TextFrame to a header or footer; then it will appear on every page where the header or footer appears. You can use absolute positions for textframes to have them anywhere on the page outside the header/footer areas.