PDFsharp & MigraDoc Foundation

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

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Thu Nov 19, 2009 4:20 pm 
Offline
Supporter

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

I am trying to create a diagram which has a number of items in it with lines connecting the items - each item is basically a table, so I am using a MigraDoc table for each, I can add these tables at specific positions by adding them to a textframe and positioning that accordingly - however when I have more than one item in the diagram, the item added 2nd is pushed down the page as if its "flowing" below the table I added first, even though the table I added first only takes up a small portion of the page. In previous print projects I Have worked on, I have rendered the objects to specific positions on the page using the renderer.RenderObject() function, but I would like to avoid using this, this time if possible as it causes other problems.
the image below shows what is happening - both tables should be on the first page, aligned with the colored blocks as the one on the first page is.
Attachment:
ScreenHunter_01 Nov. 19 16.17.jpg
ScreenHunter_01 Nov. 19 16.17.jpg [ 14.27 KiB | Viewed 7723 times ]

thanks,

Mike


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 19, 2009 4:53 pm 
Offline
PDFsharp Guru
User avatar

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

So far I didn't have that problem with MigraDoc textframes.

Maybe there's a bug in your code, maybe there's an unknown bug in MigraDoc.

Will you show us your code?

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 19, 2009 5:06 pm 
Offline
Supporter

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

here is the function I use to build the TextFrame (which contains the table)
Code:
public Table BuildAbsoluteTable(List<TableElement> cells, List<double> wids, List<double> heis, Unit xPos, Unit yPos)
        {
            if (cells.Count % wids.Count == 0 && (cells.Count / wids.Count) / heis.Count == 1)
            {
                double _tblWidth = 0;
                for (int i = 0; i < wids.Count; i++)
                {
                    _tblWidth += wids[i];
                }
                MigraDoc.DocumentObjectModel.Shapes.TextFrame _textFrame = new MigraDoc.DocumentObjectModel.Shapes.TextFrame();
                _textFrame.Left = xPos;
                _textFrame.Top = yPos;
                _textFrame.Width = _tblWidth + Unit.FromCentimeter(0.2);

                int rows = cells.Count / wids.Count;
                int _cellDataIdx = 0;
                MigraDoc.DocumentObjectModel.Tables.Table _table = _textFrame.AddTable();
                _table.TopPadding = 3;
                _table.BottomPadding = 3;
                _table.LeftPadding = 3;
                _table.RightPadding = 3;
                for (int cols = 0; cols < wids.Count; cols++)
                {
                    _table.AddColumn(wids[cols]);
                }
                try
                {
                    for (int r = 0; r < rows; r++)
                    {
                        Row _row = _table.AddRow();
                        _row.HeightRule = RowHeightRule.Exactly;
                        _row.Height = heis[r];
                        for (int c = 0; c < wids.Count; c++)
                        {
                            Cell _cell = _row.Cells[c];
                            if (cells[_cellDataIdx].format.borders.IndexOf("T") != -1)
                            {
                                _cell.Borders.Top.Width = cells[_cellDataIdx].format.borderWidth;
                            }
                            if (cells[_cellDataIdx].format.borders.IndexOf("B") != -1)
                            {
                                _cell.Borders.Bottom.Width = cells[_cellDataIdx].format.borderWidth;
                            }
                            if (cells[_cellDataIdx].format.borders.IndexOf("L") != -1)
                            {
                                _cell.Borders.Left.Width = cells[_cellDataIdx].format.borderWidth;
                            }
                            if (cells[_cellDataIdx].format.borders.IndexOf("R") != -1)
                            {
                                _cell.Borders.Right.Width = cells[_cellDataIdx].format.borderWidth;
                            }
                            Font font = MigFont.Clone();
                            font.Bold = cells[_cellDataIdx].format.bold;
                            font.Italic = cells[_cellDataIdx].format.italic;
                            font.Size = cells[_cellDataIdx].format.size;
                            font.Underline = cells[_cellDataIdx].format.underlined;
                            if (cells[_cellDataIdx].fill)
                            {
                                _cell.Shading.Color = cells[_cellDataIdx].fillColor;
                            }
                            if (cells[_cellDataIdx].mergeRight > 0)
                            {
                                _cell.MergeRight = cells[_cellDataIdx].mergeRight;
                            }
                            if (cells[_cellDataIdx].mergeDown > 0)
                            {
                                _cell.MergeDown = cells[_cellDataIdx].mergeDown;
                            }
                            BuildCell(_cell, cells[_cellDataIdx], font);
                            _cellDataIdx++;
                        }
                    }
                    CommonData.Instance.Document.LastSection.Add(_textFrame);
                }
                catch
                {

                }
                return _table;
            }
            else
            {
                return null;
            }
        }

basically the parameters - List<TableElement> cells, List<double> wids, List<double> heis, Unit xPos, Unit yPos are:
- List<TableElement> cells - this is a collection of objects that contain info about a cell, i.e. its borders, bg fill, text image etc.
- wids - a collection of doubles relating to the width of each column
- heis - a collection of doubles relating to each rows height
- xPos - the xPosition on the page to set the TextFrame to
- yPos - the yPosition on the page to set the TextFrame to

this function is called each time I create one of my diagram table "items". Also, there is another table on the page which is built usign this function:
Code:
public Table BuildSizedTable()
        {
            int rows = Cells.Count / Wids.Count;
            int _cellDataIdx = 0;
            MigraDoc.DocumentObjectModel.Tables.Table _table = new Table();
            _table.TopPadding = 3;
            _table.BottomPadding = 3;
            _table.LeftPadding = 3;
            _table.RightPadding = 3;
            for (int cols = 0; cols < Wids.Count; cols++)
            {
                _table.AddColumn(((Page.Width - LeftMargin - RightMargin) / 100) * Wids[cols]);
            }
            try
            {
                for (int r = 0; r < rows; r++)
                {
                    Row _row = _table.AddRow();
                    _row.HeightRule = RowHeightRule.Auto;
                    for (int c = 0; c < Wids.Count; c++)
                    {
                        Cell _cell = _row.Cells[c];
                        if (Cells[_cellDataIdx].format.borders.IndexOf("T") != -1)
                        {
                            _cell.Borders.Top.Width = Cells[_cellDataIdx].format.borderWidth;
                        }
                        if (Cells[_cellDataIdx].format.borders.IndexOf("B") != -1)
                        {
                            _cell.Borders.Bottom.Width = Cells[_cellDataIdx].format.borderWidth;
                        }
                        if (Cells[_cellDataIdx].format.borders.IndexOf("L") != -1)
                        {
                            _cell.Borders.Left.Width = Cells[_cellDataIdx].format.borderWidth;
                        }
                        if (Cells[_cellDataIdx].format.borders.IndexOf("R") != -1)
                        {
                            _cell.Borders.Right.Width = Cells[_cellDataIdx].format.borderWidth;
                        }
                        Font font = MigFont.Clone();
                        font.Bold = Cells[_cellDataIdx].format.bold;
                        font.Italic = Cells[_cellDataIdx].format.italic;
                        font.Size = Cells[_cellDataIdx].format.size;
                        font.Underline = Cells[_cellDataIdx].format.underlined;
                        if (Cells[_cellDataIdx].fill)
                        {
                            _cell.Shading.Color = Cells[_cellDataIdx].fillColor;
                        }
                        if (Cells[_cellDataIdx].mergeRight > 0)
                        {
                            _cell.MergeRight = Cells[_cellDataIdx].mergeRight;
                        }
                        if (Cells[_cellDataIdx].mergeDown > 0)
                        {
                            _cell.MergeDown = Cells[_cellDataIdx].mergeDown;
                        }
                        BuildCell(_cell, Cells[_cellDataIdx], font);
                        _cellDataIdx++;
                    }
                }
                CommonData.Instance.Document.LastSection.Add(_table);
            }
            catch
            {

            }
            return _table;
        }


this function is pretty similar apart from there is no text frame and the "wids" parameter is percentages of the page width - this function is tried and tested and seems to work fine, but I have only really written the BuildAbsoluteTable function today.

Maybe it's got to do with the way I add the DocumentElement (i.e. the TextFrame) to the Document's section?:

Code:
CommonData.Instance.Document.LastSection.Add(_textFrame);


doesnt seem to matter when im building "normal" tables that will flow, but obviously when absolute positioning tables, i dont want any flowing to take place.

thanks

Mike


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 23, 2009 9:02 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi, Mike!
mikesowerbutts wrote:
Maybe it's got to do with the way I add the DocumentElement (i.e. the TextFrame) to the Document's section?:

Code:
CommonData.Instance.Document.LastSection.Add(_textFrame);


doesnt seem to matter when im building "normal" tables that will flow, but obviously when absolute positioning tables, i dont want any flowing to take place.

This adds the textframe to the "current" page.

With
* AddTextFrame
* AddTextFrame
* AddParagraph
both textframes should always be on the same page.
With
* AddTextFrame
* AddParagraph
* AddTextFrame
the AddParagraph could cause a pagebreak and the textframes appear on different pages.

Maybe you just have to set
Code:
_textFrame.WrapFormat.Style = WrapStyle.Through;

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 23, 2009 10:43 am 
Offline
Supporter

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

that seems to have worked, but I had to set:
Code:
_textFrame.RelativeVertical = RelativeVertical.Margin;
_textFrame.RelativeHorizontal = RelativeHorizontal.Margin;

also becuase otherwise the textframes seemed to be ignoring their Y position and all aligning to the top of the page for soem reason - setting this RelativeVertical property seems to have solved that issue though.

thnaks very much for your help - its greatly appreciated!

I am also still stuck on the ost i raised las week about page numbering when a page overflows onto a 2nd page, any pointers on that would be appreciated.

thanks,

mike


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 398 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