PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Oct 31, 2024 11:00 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sun Oct 01, 2023 7:53 am 
Offline

Joined: Mon Aug 07, 2023 9:07 pm
Posts: 10
If paragraph is added to textframe and paragraph height is extended to two lines, line in page is only partially visible sometimes.

Example is in
https://github.com/empira/PDFsharp/file ... aviour.pdf

To reproduce run code in MigraDoc template:

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;
    }

Full VS solution is in https://github.com/empira/PDFsharp/file ... ofpage.zip

How to make all lines fully visible? In real application paragraph height is not known and Migradoc does not provide method to get paragraph height. So textframe height cannot increased by code.

Using PDFsharp-MigraDoc 6.0.0-preview-3


Top
 Profile  
Reply with quote  
PostPosted: Sun Oct 01, 2023 5:05 pm 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1000
Location: CCAA
Textframes do not break to the next page, this is by design.
Calles must ensure that a textframe fits onto the page.

For normal text, it is recommend to have the text in the body of the section or in a table.
Note that table cells will not break across pages.
Tables will break at cell boundaries.
Paragraphs in the body will break at line boundaries.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 02, 2023 8:45 am 
Offline

Joined: Mon Aug 07, 2023 9:07 pm
Posts: 10
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.


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 02, 2023 12:13 pm 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1000
Location: CCAA
TextFrames are usually used to place text at absolute positions on a page. When you place them at an absolute position, make sure the width and height also fits. If you want to have them flow with the body text, consider using a Table or a Paragraph outside a TextFrame. What's the purpose of the TextFrame in your sample code? I do not see a need for a TextFrame here.

MigraDoc allows SpaceBefore and left indent for paragraphs. And AFAIK MigraDoc breaks "normal" non-floating TextFrames to the next page. So either use non-floating TextFrames that will break to the next page or use regular paragraphs with SpaceBefore and left indent.
Or use floating TextFrames and take responsibility for page breaks with PDFsharp/MigraDoc up to version 6.0.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group