0

I am using MigraDoc to generate a PDF. I want to align some content to the bottom of the last page. This is boilerplate disclaimer information that my company always includes in these types of documents. The goal is to keep the content altogether and always have it appear just above the footer on the last page. If there isn't room on the last page of actual content to keep it together, there should be a page break and the boilerplate content will be on a page by itself.

I would like to do this without measuring the height of the content.

I get the impression that I can use TextFrame to assist with this in some way, but I can't find any documentation on it. The questions and examples I've found online refer to being able to "absolutely position" the TextFrame, but none of the examples seem to do that, exactly.

As a starting point, I am trying to position a paragraph of text in the way I described on an otherwise blank page. Here's my latest experiment:

    static void AddBoilerPlate(Section section) {
        var sectionWidth = PdfSharp.PageSizeConverter.ToSize(PageSize.Letter).Width - section.Document.DefaultPageSetup.LeftMargin.Point -
            section.Document.DefaultPageSetup.RightMargin.Point;

        section.AddPageBreak();
        var frame = section.AddTextFrame();
        frame.RelativeVertical = RelativeVertical.Page;
        frame.Width = sectionWidth;
        frame.Top = ShapePosition.Bottom;
        frame.AddParagraph(DisclaimerText);
    }

The text starts just above the footer (the blue line in this screenshot) and then runs over the footer:

enter image description here

Once I get a paragraph of text aligned, then I think I will be able to use a table with one column and one row instead, and then put all of my content in there.

Update: here is a screenshot showing my goal (faked using a page break and SpaceBefore):

enter image description here

Update: here are some related articles that don't quite get me where I'm trying to go:

Update: Note that adding a height to the TextFrame does make the text align the way I need it to. It's not ideal, because I would rather not hard-code the height. But it does produce the desired effect:

    static void AddBoilerPlate(Section section) {
        var sectionWidth = PdfSharp.PageSizeConverter.ToSize(PageSize.Letter).Width - section.Document.DefaultPageSetup.LeftMargin.Point -
            section.Document.DefaultPageSetup.RightMargin.Point;

        section.AddPageBreak();
        var frame = section.AddTextFrame();
        frame.RelativeVertical = RelativeVertical.Page;
        **frame.Height = new Unit(75, UnitType.Millimeter);**
        frame.Width = sectionWidth;
        frame.Top = ShapePosition.Bottom;
        frame.AddParagraph(DisclaimerText);
    }

Update: Note, though, that setting the TextFrame height doesn't resolve the ultimate issue. Content added before the boilerplate should push the boilerplate to the next page if there isn't enough space for it, and that's not happening.

Community
  • 1
  • 1
David Cater
  • 415
  • 3
  • 15

1 Answers1

0

Update: After trying it out myself (I've had the same Problem), add an invisible element with the Height you want to have just before the bottom element. In case the invisible Element doesn't fit it will seem that the page break occurred because of the bottom element. Works like a charm. (tip I added a border to both elements for testing so I was able to make sure the layout was proper)

George
  • 75
  • 1
  • 9