PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat May 04, 2024 9:01 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: Wed Jul 08, 2009 4:00 pm 
Offline
Supporter

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
Hi,

I am creating a table with a lot of rows, for some reason, the table will not break over multiple pages, each row is quite small - there are just a lot of them! instead of breaking onto multiple pages, the rows which wont fit on the starting page are just cut off.

I have tried setting KeepTogether to false but it doesnt seem to make any difference!

here is the function which creates the table:

Code:
public MigraDoc.DocumentObjectModel.Tables.Table buildSizedTable(int rows, List<int> colWidths, List<TableElement> cellData, MigraDoc.DocumentObjectModel.Font font)
        {
            int _cellDataIdx = 0;
            MigraDoc.DocumentObjectModel.Tables.Table _table = new Table();
            _table.TopPadding = 3;
            _table.BottomPadding = 3;
            _table.LeftPadding = 3;
            _table.RightPadding = 3;
            //_table.KeepTogether = false;
            MigraDoc.DocumentObjectModel.Font _font = font.Clone();
            for (int cols = 0; cols < colWidths.Count; cols++)
            {
                _table.AddColumn(((page.Width - leftMargin - rightMargin) / 100) * colWidths[cols]);
            }
            try
            {
                for (int r = 0; r < rows; r++)
                {
                    Row _row = _table.AddRow();
                    _row.HeightRule = RowHeightRule.Auto;

                    for (int c = 0; c < colWidths.Count; c++)
                    {
                        Cell _cell = _row.Cells[c];
                        if (cellData[_cellDataIdx].format.borders.IndexOf("T") != -1)
                        {
                            _cell.Borders.Top.Width = cellData[_cellDataIdx].format.borderWidth;
                        }
                        if (cellData[_cellDataIdx].format.borders.IndexOf("B") != -1)
                        {
                            _cell.Borders.Bottom.Width = cellData[_cellDataIdx].format.borderWidth;
                        }
                        if (cellData[_cellDataIdx].format.borders.IndexOf("L") != -1)
                        {
                            _cell.Borders.Left.Width = cellData[_cellDataIdx].format.borderWidth;
                        }
                        if (cellData[_cellDataIdx].format.borders.IndexOf("R") != -1)
                        {
                            _cell.Borders.Right.Width = cellData[_cellDataIdx].format.borderWidth;
                        }
                        font.Bold = cellData[_cellDataIdx].format.bold;
                        font.Italic = cellData[_cellDataIdx].format.italic;
                        font.Size = cellData[_cellDataIdx].format.size;
                        font.Underline = cellData[_cellDataIdx].format.underlined;
                        if (cellData[_cellDataIdx].fill)
                        {
                            _cell.Shading.Color = cellData[_cellDataIdx].fillColor;
                        }
                        if (cellData[_cellDataIdx].mergeRight > 0)
                        {
                            _cell.MergeRight = cellData[_cellDataIdx].mergeRight;
                        }
                        if (cellData[_cellDataIdx].mergeDown > 0)
                        {
                            _cell.MergeDown = cellData[_cellDataIdx].mergeDown;
                        }
                        buildCell(_cell, cellData[_cellDataIdx], font);
                        _cellDataIdx++;
                    }
                }
                _table.KeepTogether = false;

                document.LastSection.Add(_table);
            }
            catch
            {

            }
            return _table;
        }


The cellData object in the parameters is basically an array of objects holding styling information for each cell.

Im really stuck on this - I am creating quite a lot of print documents, all of which have an unfixed number of rows in each table, so this is a big problem for me!

Any ideas?


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 10, 2009 9:25 am 
Offline
Supporter

Joined: Fri May 15, 2009 3:28 pm
Posts: 96
ok this was to do with how i was rendering/adding pages rather than the tables not splitting properly - fixed now!


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 01, 2009 8:44 pm 
Offline

Joined: Tue Sep 01, 2009 8:36 pm
Posts: 4
Hi.. i am stuck with the problem as yours - hundreds of rows coming from a database and not being able to break table over multiple pages. Could you please tell me how you fixed this problem by rendering/adding pages to accommodate huge tables across pages. Any input/code would help.

Thanks.. Ragu


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 09, 2009 1:49 pm 
Offline

Joined: Tue Sep 01, 2009 8:36 pm
Posts: 4
Well, i managed to solve this. For those who might face similar issues, here's what helped me:
- used MigraDoc entirely, the Section and Renderer objects
- created table using Tables.Table and adding rows to it (as they come from db)
- adding the table to section > Section.Add(table)
- finally adding the section to the PDF document, using the Renderer

Now the table stretches across multiple pages.. Thanks indeed to PDFsharp and MigraDoc :)


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