PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 1:02 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Overlapping text
PostPosted: Wed May 22, 2013 1:30 pm 
Offline

Joined: Wed May 22, 2013 1:09 pm
Posts: 2
Hi,

I'm new to Migradoc and I've encountered a problem with text overlapping. I've searched for a solution to this, but can't seem to find a simple one (or one which is explained well enough for me to be able to understand- I'm very new to this!!).

Here is the problem:
Attachment:
overlapping problem.JPG
overlapping problem.JPG [ 32.49 KiB | Viewed 5855 times ]

Note that the 'Some data gets loaded here' should fit on the line, but might not.

The code creates a table (maintable) with 2 columns, then adds a textframe to each column and a table within each textframe. I've worked out that the row in the maintable does not resize to the height of the row in the table within. I believe this is because the textframe does not expand to fit the table inside of it.

Here is the full code:
Code:
            // add section
            Section sec1 = doc.AddSection();

            Table table;
            Column column;
            Row row;
            Paragraph para;

            // create table for 2 header sections
            Table maintable = sec1.AddTable();
            var maincolumn = maintable.AddColumn();
            maincolumn.Width = Unit.FromMillimeter(110);
            maincolumn = maintable.AddColumn();
            maincolumn.Width = Unit.FromMillimeter(60);
            Row mainrow = maintable.AddRow();
            mainrow.HeightRule = RowHeightRule.Auto;

            // add table and format
            var textframe = mainrow.Cells[0].AddTextFrame();
            table = textframe.AddTable();
            table.Borders.Width = 0.5;
            table.LeftPadding = 5;
            column = table.AddColumn();
            column.Width = Unit.FromMillimeter(80);
            row = table.AddRow();

            // add text
            para = row[0].AddParagraph("Title 1");
            para.Style = "h1";
            para = row[0].AddParagraph();
            para.AddFormattedText("Sub title1: ", TextFormat.Bold);
            para.AddFormattedText("Some data gets loaded here");
            para = row[0].AddParagraph();
            para.AddFormattedText("Sub title2: ", TextFormat.Bold);
            para.AddFormattedText("Some data gets loaded here");
            para = row[0].AddParagraph();
            para.AddFormattedText("Sub title3: ", TextFormat.Bold);
            para.AddFormattedText("Some data gets loaded here");
            para = row[0].AddParagraph();
            para.AddFormattedText("Sub title4: ", TextFormat.Bold);
            para.AddFormattedText("Some data gets loaded here");
            para = row[0].AddParagraph();
            para.AddFormattedText("Sub title5: ", TextFormat.Bold);
            para.AddFormattedText("Some data gets loaded here");

            // create frame to add to so can float to the right
            var frame1 = mainrow.Cells[1].AddTextFrame();
            frame1.Top = 0;
            frame1.Left = ShapePosition.Right;
            frame1.Width = Unit.FromMillimeter(60);

            table = frame1.AddTable();
            table.Borders.Width = 0.5;
            table.LeftPadding = 5;
            column = table.AddColumn();
            column.Width = Unit.FromMillimeter(60);
            row = table.AddRow();

            // add text
            para = row[0].AddParagraph();
            para.AddFormattedText("Report Period: ", TextFormat.Bold);
            para.AddFormattedText(StartDate + " to " + EndDate);
            para = row[0].AddParagraph();
            para = row[0].AddParagraph("Some data gets loaded here");

            para = sec1.AddParagraph("KEY STATISTICS - Period (" + StartDate + "/" + EndDate + ")");
            para.Style = "h1";
            para = sec1.AddParagraph("Some more data");
            para.Style = "bold";

            // create table
            table = sec1.AddTable();
            column = table.AddColumn(50);
            column = table.AddColumn(50);
            column = table.AddColumn(50);
            column = table.AddColumn(50);
            column = table.AddColumn(50);
            Row titlerow = table.AddRow();
            row = table.AddRow();

            para = titlerow[1].AddParagraph("Column heading 1");
            titlerow.Cells[1].MergeRight = 1;
            para = titlerow[3].AddParagraph("Column heading 2");
            titlerow.Cells[3].MergeRight = 1;


Can somebody please provide a solution or workaround to this?

Thanks in advance,

Nicola


Top
 Profile  
Reply with quote  
 Post subject: Re: Overlapping text
PostPosted: Wed May 22, 2013 2:43 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi!

Avoid TextFrames (as TextFrames do not grow with their contents).

Try to use a single table. Make three rows, use MergeRight and MergeDown to get the layout you need.
You can have a single frame around several cells, so getting the sample layout you are showing with a single table should be rather simple (assuming the right frame is always smaller than the left frame).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Overlapping text
PostPosted: Wed May 22, 2013 3:28 pm 
Offline

Joined: Wed May 22, 2013 1:09 pm
Posts: 2
Brilliant! Thank you, that works perfectly :D


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 430 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