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:45 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: Thu Mar 19, 2009 7:24 am 
Offline

Joined: Fri Oct 24, 2008 12:24 pm
Posts: 13
Location: Brisbane, Australia
Is it possible to make a TextFrame increase its Height to contain its content?

for example the following code snippet creates a TextFrame with a border but the borders only 'contain' lines 1 to 6. Lines 7 to 9 fall outside the borders.

Code:
        private void AddLeftBox(Section section)
        {
            var frame = section.AddTextFrame();
            frame.Width = new Unit(80.0, UnitType.Millimeter);
            frame.LineFormat.Width = Unit.FromPoint(0.5);
            for (int i = 1; i < 10; i++)
                frame.AddParagraph("Line " + i);
        }


Failing an automatic way of doing this is there a way to measure the contents of the TextFrame after they have been added and then retrospectively set the TextFrame.Height property[/code]


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Mar 19, 2009 7:52 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3111
Location: Cologne, Germany
Workaround: add a table to the textframe and set the border of the table.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Mar 19, 2009 7:46 pm 
Offline

Joined: Fri Oct 24, 2008 12:24 pm
Posts: 13
Location: Brisbane, Australia
Thanks Thomas.

I was hoping not to clutter the structure of the document like that but I shall take your suggestion on board.

Is this unimplemented functionality/feature in MigraDoc or is there a reason why the TextFrame behaves that way?

Cheers
Simon


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Mar 20, 2009 1:40 am 
Offline

Joined: Fri Oct 24, 2008 12:24 pm
Posts: 13
Location: Brisbane, Australia
Just to add closure for others' benefit - this is an acceptable workaround for my situation :D

Code:
private void AddLeftBox(Section section)
{
    var frame = section.AddTextFrame();

    Table table = frame.AddTable();
    table.Borders.Width = 0.5;
    table.LeftPadding = 0;

    var column = table.AddColumn();
    column.Width = Unit.FromMillimeter(80);

    Row row = table.AddRow();

    for (int i = 1; i < 10; i++)
        row[0].AddParagraph("Line " + i);
}


The line
Code:
table.LeftPadding = 0;
ensures that the table is aligned with other paragraph borders in my document. You may not need this in other applications (as appropriate).

Thanks again


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 35 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