PDFsharp icon indicating copy to clipboard operation
PDFsharp copied to clipboard

Overflowing paragraph text in TextFrame is not fully visible in end of page

Open kobruleht opened this issue 1 year ago • 4 comments

Expected Behavior

Last line in page should be fully visible (see attached pdf file).

Actual Behavior

Half of last line in end of first page is visible.

Steps to Reproduce the Behavior

Run attached solution

Code:

    static Document CreateDocument()
    {
        // Create a new MigraDoc document.
        var document = new Document { };
        // Add a section to the document.
        var section = document.AddSection();
        section.PageSetup.BottomMargin = 0;
        section.PageSetup.TopMargin = 0;
        for (int p = 1; p < 100; p++)
        {
            var textFrame = section.AddTextFrame();
            textFrame.RelativeVertical = RelativeVertical.Line;
            textFrame.WrapFormat.DistanceTop = Unit.FromCentimeter(0.11);
            textFrame.Height = Unit.FromCentimeter(0.47);
            var paragraph = textFrame.AddParagraph();
            paragraph.Format.Font.Name = "Times New Roman";
            paragraph.Format.Font.Size = 10;
            paragraph.AddText("Maksekorraldus 123456");
            paragraph.Format.SpaceBefore = 0;
            paragraph.Format.SpaceAfter = 0;
        }
        return document;
    }

texttruncatedinendofpage.zip actual behaviour.pdf

Using PDFsharp-MigraDoc 6.0.0-preview-3

kobruleht avatar Oct 01 '23 07:10 kobruleht

Textframes do not break to the next page, this is by design. Callers must ensure that a textframe fits onto the page.

TH-Soft avatar Oct 01 '23 17:10 TH-Soft

MigraDoc should add page break before such textframe. This issue occurs since paragraph inside textframe stretches to two lines but textframe height is only single line.

kobruleht avatar Oct 01 '23 19:10 kobruleht

MigraDoc should add page break before such textframe.

The software architect of MigraDoc decides what MigraDoc should do. I'll ask him about it.

ThomasHoevel avatar Oct 02 '23 07:10 ThomasHoevel

PDFs are created from report template which contains text fields having left, height, width and top properties:

image

Paragraph does not have position and size. So text is added to paragraph inside TextFrame. Paragraph contains variable number of lines and has variable height. Page break should inserted if top position + height is greater that printable area in page.

If textFrame is not used, it is not possible to specify paragraph width.

There are no method to get stretched paragraph height. If paragraph height is known, TextFrame height can set to this value and non-floating TextFrames are probably paged correctly.

kobruleht avatar Oct 02 '23 08:10 kobruleht