PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Fast table rendering in MigraDoc
https://forum.pdfsharp.net/viewtopic.php?f=2&t=679
Page 1 of 2

Author:  espeedy [ Tue Mar 17, 2009 1:49 pm ]
Post subject:  Fast table rendering in MigraDoc

Hello

First of all, thank you for this excellent piece of software.

I see in your announcement, that MigraDoc is very slow when rendering large tables.

I am generating large tables (with 10.000 or more rows) which means about 400 pages. It takes about 10 minutes to generate.

You wrote that you will be fixing this slow rendering, but do you have any idea of when?

Thank you

Author:  michas45 [ Wed Nov 03, 2010 9:26 am ]
Post subject:  Re: Fast table rendering in MigraDoc

This post was not replied for quite a long time. I have same problem, slow rendering of tables.

Can you give roughly term of solving that issue?

It has been almost year from last version release so I'm really looking forward next relese with this issue fixed :)

Regards

Author:  pakeha_by [ Wed Jan 19, 2011 5:38 am ]
Post subject:  Re: Fast table rendering in MigraDoc

I patched sources to speed up table rendering, it became 2 - 3 times faster (probably even better on bigger tables).
Can share the patch if you want.

Author:  Orestone [ Wed Jan 19, 2011 2:42 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

@ pakeha_by

Please share the patch - I am sure this would be of interest to many people

Author:  jeffhare [ Thu Jan 20, 2011 3:31 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

I found that when rendering paragraph content within a table cell, the XFonts are not cached and there seems to be a huge amount of time spent creating fonts in order to measure text heights/widths, etc to see whether a given word fits in the area or not.

Another thing that seriously slowed down table rendering was the use of reflection to get the row/column information of a cell. Caching the cell's row/column info after fetching it the first time made a huge difference as I recall also... Generally speaking the use of reflection is what is causing a majority of the slowdowns. The reflection (Meta) code is clever and helps simplify MDDL loading some, but seems to really hurt performance for those who are generating very large or huge numbers of documents. From an interactive standpoint, its not too bad, but I wonder if that many people are using this library for writing interactive PDF editors vs converters or alternate output formats for some other application.

I would also be interested in the techniques you used to speed up table rendering, so please post a zip if you can of your new code. :)

Author:  pakeha_by [ Wed Mar 23, 2011 8:58 am ]
Post subject:  Re: Fast table rendering in MigraDoc

Sorry guys, I didn't receive notifications from this thread.

Patch is attached to this post, source codes are availalbe at https://pdfsharp.svn.codeplex.com/svn/MigraDoc/code

If somebody will use this patch please let me know what's the performance inprovement in your case.

Attachments:
TableRenderPatch.zip [7.2 KiB]
Downloaded 147840 times

Author:  Magges [ Thu Mar 24, 2011 11:30 am ]
Post subject:  Re: Fast table rendering in MigraDoc

How can I aply this patch to my Sources?

Author:  pakeha_by [ Thu Mar 24, 2011 9:18 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

Here is new version of the patch, there was a bug in rendering of vertically merged cells in some circumstances.

To apply patch use TortoiseSVN command "Apply Patch..." or use external tool http://gnuwin32.sourceforge.net/downlinks/patch-bin-zip.php: patch.exe -p0 < TableRendering.patch

Attachments:
TableRendering.zip [7.21 KiB]
Downloaded 134795 times

Author:  venramesh [ Tue Mar 29, 2011 6:35 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

With this fix the Rendering is very fast and Thanks to the PDFSharp and Migradoc Team :-)

Without the fix it took more than 5 minutes to render a 40+ pages document with approximately 5000 rows of data. After the fix it is now taking only a maximum of 12 seconds :-)

Author:  pakeha_by [ Tue Mar 29, 2011 9:36 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

I'm not PDFSharp team member, just regular library user. :)

Thank you for feedback, may be it will speed up process to include patch to release

Author:  MarcelW [ Mon Apr 04, 2011 7:35 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

Great! Thanks for sharing pakeha_by!

Author:  TimJohnston [ Tue Apr 12, 2011 8:40 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

Do you think its possible to post the updated library/dll or even repackage the update into the current release/installer?

It would be great if the team could check the code and roll it into an updated release (given the huge performance improvement), that would make it much easier for those unfamiliar with SVN or recompiling libraries etc...

Thanks, TJ.

Author:  roelvandersteen [ Fri Apr 15, 2011 9:18 am ]
Post subject:  Please submit this patch to pdfsharp.codeplex.com

@pakeha_by: Thank you very much for this patch!

I noticed that you submitted the patch to migradoc.codeplex.com, but it seems to me that pdfsharp.codeplex.com is the official home for both PDFsharp and MigraDoc. Maybe you want to consider submitting the patch at the PDFsharp CodePlex site as well...

Thanks again, I hope this patch will be included in the official release soon.

Author:  pakeha_by [ Sun Apr 17, 2011 12:24 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

@roelvandersteen

Both sites (migradoc.codeplex.com and pdfsharp.codeplex.com) are managed by same people so it doesn't really matter where to upload patch. But thank you for the tip, I uploaded final version of the patch to migradoc.codeplex.com for consistency.

Author:  vmp5 [ Thu Jul 21, 2011 9:23 am ]
Post subject:  Re: Fast table rendering in MigraDoc

Thanks for the patch! Was afraid i had to do it myself - very happy i didn't need to :-)
Performance was boosted by factor >10 in my case!

Author:  PFA38 [ Fri Aug 12, 2011 8:16 am ]
Post subject:  Re: Fast table rendering in MigraDoc

Hi guys,

I want to patch, but I don't know how to. :oops:

Can someone explain me, step by step how to apply this patch ? :roll:

or better for me give a link to the patched dll ?

Thanks

regards,

PFa38

Author:  pakeha_by [ Fri Aug 12, 2011 12:35 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

Here is compiled assemblies with applied patch: http://www.pakeha_by.my-webs.org/MigraDocFastTableRender.html

As I asked earlier in this thread, please let me know how faster it become.

Cheers

Author:  PFA38 [ Fri Aug 12, 2011 1:51 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

Awesome !

2 minutes -> 9 seconds.

for a 5 pages document.
In each page an array (approx 70 cols and 35 row) of small arrays (1 row an 1 col) in 30% of cells

Thanks ! :D

Author:  hybridview [ Fri Aug 26, 2011 2:04 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

Many, many thanks for this patch. I cannot give an exact figure for performance improvement because my rendering wasn't finishing. Now, it finishes a complex, 800 row table in under 2 minutes on a single core of my Core2 developer box.

Author:  sfvaleriano [ Fri Sep 23, 2011 4:45 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

After apply this patch the render of table is very fast. But there is a problem.

After applying the patch you no longer have the ability to hide the border rows
For example the following code no longer works

Code:
           
Dim t As New Table
Dim r As Row
For index As Integer = 1 To 100
r = t.AddRow
r.Borders.Bottom.Visible = (index Mod 2 = 0)
Next


thanks,
Valeriano

Author:  pakeha_by [ Mon Sep 26, 2011 3:41 am ]
Post subject:  Re: Fast table rendering in MigraDoc

Valeriano,

could you please clarify what doesn't work in your case - what is expected/old result and what's new outcome after patch?
If you want to hide borders between odd and event rows you also need hide TOP border of neighbor from bottom:

Code:
     
for (int index = 0; index < 100; index++) {
        Row row = table.AddRow();
        row.Cells[0].AddParagraph("This is row");
        row.Borders.Bottom.Visible = (index % 2 == 0);
        row.Borders.Top.Visible = (index % 2 == 1);
      }

Author:  sfvaleriano [ Mon Sep 26, 2011 11:35 am ]
Post subject:  Re: Fast table rendering in MigraDoc

Hi,

before the patch was hiding at the bottom border of the row simply with

Code:
row.Borders.Bottom.Visible = False


after the patch I had to use the solution proposed by you.

Now it works.

thanks,
Valeriano

Author:  johnbc [ Tue Oct 18, 2011 4:45 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

Well Done!!! I received incredible speed increase in my usage.
Previously a 40x30 grid of 6 pages took 112 seconds to render, but now it takes only 7 seconds.
4 pages were 78 seconds and now it takes 4 seconds.
Congratulations on a job well done, and Thank you!
:mrgreen:

Author:  kko [ Tue May 22, 2012 2:02 am ]
Post subject:  Re: Fast table rendering in MigraDoc

1200 rows/3 columns
got down to 2 seconds from 120 seconds. Thanks A LOT!

Author:  putenec [ Sat Sep 15, 2012 9:39 am ]
Post subject:  Re: Fast table rendering in MigraDoc

Hello everyone, we are glad and thankful for the patch, its really faster.

There is one problem. When you have some scenario with merged right cells the borders don't work properly

To be more specific. When you have let's say a table with 6 columns and you MergeRight 2 from from index 0 and again MergeRight 2 from index 3 somehow the left margin gets copied to the right margin of the merged cell and it is drawn even though it should not. I was trying to debug the library, and found out, the right margin property is set even though it should not be. But I wasn't able find out where this exactly happens. I didn't want to give it too much time, before I ask here.

Here is the code:

Definition of the styles, I am sending just the relevant part:

Code:
bgColor = new Color(234, 237, 245);
tableEdgeType = Edge.Left;
tableEdgeStyle = MigraDoc.DocumentObjectModel.BorderStyle.Single;
tableEdgeWidth = 0.5;
itemRowBorder.Width = 0.5;
itemRowBorder.Style = MigraDoc.DocumentObjectModel.BorderStyle.Dot;
style = this.Document.Styles.AddStyle("Table", "Classic");
style.Font.Size = 12;
style.ParagraphFormat.SpaceBefore = 1;
style.ParagraphFormat.SpaceAfter = 1;
style.ParagraphFormat.LeftIndent = 1;
style = this.Document.Styles.AddStyle("Text", "Classic");
style.Font.Name = "Tahoma";
style.Font.Size = 12;
style = this.Document.Styles.AddStyle("TextTitle", "Text"); //text title e.g. "Faktura"
style.Font.Size = 20;
style.Font.Bold = true;
style.ParagraphFormat.SpaceBefore = 0;

//define styles for All tables in invoice except item and summary table
style = this.Document.Styles.AddStyle("TableRowAll", "Table");
style.Font.Size = 10;
style = this.Document.Styles.AddStyle("TableRowAllLarge", "Table");
style.Font.Size = 12;
style = this.Document.Styles.AddStyle("TableRowAllSmall", "Table");
style.Font.Size = 8;


and here is the code that creates table itself:

Code:
Table table = section.AddTable();
table.Style = "TableRowAll";

// Left side of the table
Column column = table.AddColumn("2.69cm");
column = table.AddColumn("3.8cm");
column = table.AddColumn("2.49cm");

// right side of the table
column = table.AddColumn("2.69cm");
column = table.AddColumn("3.8cm");
column = table.AddColumn("2.49cm");

// Left part of the header
Row row = table.AddRow();
row.Cells[0].MergeRight = 2;
row.Cells[0].AddParagraph(ReportResources.InvoiceDodavatel.ToUpper() + ":");
row.Cells[0].Shading.Color = bgColor;

//*****************************
// problem here!
row.Cells[0].Borders.Left.Style = tableEdgeStyle;
row.Cells[0].Borders.Left.Width = tableEdgeWidth;
// it should draw just the left margin, but it draws right margin as well
//*****************************

// Right part of the header
row.Cells[3].MergeRight = 2;
row.Cells[3].AddParagraph(ReportResources.InvoiceOdberatel.ToUpper() + ":");
row.Cells[3].Shading.Color = bgColor;


Image

Thanks for help,

Michal

Author:  Thomas Hoevel [ Mon Sep 17, 2012 8:11 am ]
Post subject:  Re: Fast table rendering in MigraDoc

Hi, Michal!
putenec wrote:
I didn't want to give it too much time, before I ask here.
I presume the error occurs only with the patched version, not the original version?

Author:  pakeha_by [ Mon Sep 17, 2012 9:09 am ]
Post subject:  Re: Fast table rendering in MigraDoc

Hi Michal

There is a bug in patched version - when it calculates border width it does not take into consideration cell merging.

MergedCellList.GetNeighbor() function should look like that:
Code:
    private Cell GetNeighbor(CellInfo cellInfo, NeighborPosition position)
    {
      var cell = cellInfo.Cell;

      switch (position) {
        case NeighborPosition.Left:
          if (cellInfo.BlockCol > 0)
            return CellInfos[cellInfo.BlockRow, cellInfo.BlockCol - 1].Cell;
          break;

        case NeighborPosition.Right:
          if (cellInfo.BlockCol + cell.MergeRight < ColCount - 1)
           return CellInfos[cellInfo.BlockRow, cellInfo.BlockCol + cell.MergeRight + 1].Cell;
          break;

        case NeighborPosition.Top:
          if (cellInfo.BlockRow > 0)
            return CellInfos[cellInfo.BlockRow - 1, cellInfo.BlockCol].Cell;
          break;

        case NeighborPosition.Bottom:
          if (cellInfo.BlockRow + cell.MergeDown < RowCount - 1)
           return CellInfos[cellInfo.BlockRow + cell.MergeDown + 1, cellInfo.BlockCol].Cell;
          break;
      }



If you are using pre-built assemblies then let me know, I'll create new version of them.

Andrew

Author:  putenec [ Tue Sep 18, 2012 10:25 am ]
Post subject:  Re: Fast table rendering in MigraDoc

Dear Andrew,

thank you for the fix. For what I have tried so far, it works fine. I am surprised this issue has not been addressed earlier.
If I find something in the future, I will let you know.

Best regards,

Michal

Image

Author:  putenec [ Tue Sep 18, 2012 10:33 am ]
Post subject:  Re: Fast table rendering in MigraDoc

Thomas Hoevel wrote:
Hi, Michal!
putenec wrote:
I didn't want to give it too much time, before I ask here.
I presume the error occurs only with the patched version, not the original version?


Hello Thomas,

the original version works fine, doesn't have this problem. But as it has been mentioned here, it is very slow while working with tables. Do you consider to upgrade the libraries with this improvement in the future?

Best regards,

Michal

Author:  Thomas Hoevel [ Tue Sep 18, 2012 10:51 am ]
Post subject:  Re: Fast table rendering in MigraDoc

We know that table rendering is slow, very slow.
We will make it faster.

But we will verify that tables rendered with the new, faster code will look the same as tables rendered with the old, slow "reference implementation".

Author:  putenec [ Wed Sep 19, 2012 5:50 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

Hello guys,

If we use the same code as in my first post for the definition of styles and change line number two from tableEdgeType = Edge.Left; to tableEdgeType = Edge.Box; and then we want to use SetEdge method to draw the edge:

Code:
Table table = section.AddTable();
table.Style = "TableRowAll";

// Left side of the table
Column column = table.AddColumn("2.7cm");
column = table.AddColumn("3.8cm");
column = table.AddColumn("2.5cm");

// right side of the table
column = table.AddColumn("2.7cm");
column = table.AddColumn("3.8cm");
column = table.AddColumn("2.5cm");//column for logo

// Left part of the header
Row row = table.AddRow();
row.Cells[0].MergeRight = 2;
row.Cells[0].AddParagraph(ReportResources.InvoiceDodavatel.ToUpper() + ":");
row.Cells[0].Shading.Color = bgColor;
//row.Cells[0].Borders.Style = tableEdgeStyle;
//row.Cells[0].Borders.Width = tableEdgeWidth;

// Right part of the header
row.Cells[3].MergeRight = 2;
row.Cells[3].AddParagraph(ReportResources.InvoiceOdberatel.ToUpper() + ":");
row.Cells[3].Shading.Color = bgColor;

//*******************
// problematic part
table.SetEdge(0, 0, 2, table.Rows.Count, tableEdgeType, tableEdgeStyle, tableEdgeWidth);
//*******************


Here is what happens:

Image

If you draw it manually, uncomment these two lines
Code:
row.Cells[0].Borders.Style = tableEdgeStyle;
row.Cells[0].Borders.Width = tableEdgeWidth;


and comment out the SetEdge line, it draws it correctly.

Image

Thanks,

Michal

Author:  pakeha_by [ Wed Sep 19, 2012 10:00 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

Hi Michal
putenec wrote:
I am surprised this issue has not been addressed earlier.

I assume very few people uses patched version and even fewer has got complex borders/styling - you were first one who met this problem.

Code:
//*******************
// problematic part
table.SetEdge(0, 0, 2, table.Rows.Count, tableEdgeType, tableEdgeStyle, tableEdgeWidth);
//*******************

Please note that column 1 has got MergedRight = 2 so merged cell is 3-columns wide and right edge of your .setEdge is coming through it.

If you call table.SetEdge(0, 0, 3, ... then everything is OK.


Andrew

Author:  anders [ Thu Sep 20, 2012 11:09 am ]
Post subject:  Re: Fast table rendering in MigraDoc

Thomas Hoevel wrote:
We know that table rendering is slow, very slow.
We will make it faster.

But we will verify that tables rendered with the new, faster code will look the same as tables rendered with the old, slow "reference implementation".


Hi Thomas.

Do you have an idea of ​​when you are ready with a "faster rendering" version?
Regards Anders

Author:  putenec [ Fri Sep 21, 2012 12:46 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

anders wrote:
Thomas Hoevel wrote:
We know that table rendering is slow, very slow.
We will make it faster.

But we will verify that tables rendered with the new, faster code will look the same as tables rendered with the old, slow "reference implementation".


Hi Thomas.

Do you have an idea of ​​when you are ready with a "faster rendering" version?
Regards Anders


I would suggest for you to take the latest version of the patch, you can patch files easily with the patch.exe, using command prompt, just copy everything into one folder. For example:

1. Create C:\migra
2. Download: http://gnuwin32.sourceforge.net/downlin ... in-zip.php into C:\migra
3. Extract the patch-2.5.9-7-bin.zip
4. Go to C:\migra\bin
5. Copy the following folders including subfolders from your MigraDoc library:
MigraDoc.DocumentObjectModel
MigraDoc.Rendering
6. the content of your C:\migra\bin folder should look like this:
patch.exe
TableRendering.patch
MigraDoc.DocumentObjectModel
MigraDoc.Rendering
7. run cmd and cd into C:\migra\bin
8. run patch.exe -p0 < TableRendering.patch

After this procedure copy the two patched MigraDoc folders back into your project.

Read post from Andrew, where he talks about fixing one method called GetNeighbor. Verify whether the correct code is inside, if not replace the code manually.

Build your project and use fast table rendering.

Michal

Author:  pakeha_by [ Fri Sep 21, 2012 10:48 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

In case somebody needs compiled assemblies, I've uploaded patched 1.32 assemblies and patch itself to the site http://pakeha_by.my-webs.org/MigraDocFastTableRender.html. It also includes above fix for borders between merged cells.

Author:  mompox [ Wed Sep 26, 2012 4:29 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

Hi pakeha_by,
Can you upload assemblies compiled in Release mode? The Pdf files generated by the debug mode assemblies are much larger.
Thanks

Author:  pakeha_by [ Thu Sep 27, 2012 10:46 am ]
Post subject:  Re: Fast table rendering in MigraDoc

mompox wrote:
Hi pakeha_by,
Can you upload assemblies compiled in Release mode? The Pdf files generated by the debug mode assemblies are much larger.
Thanks


No problem, I've added Release assemblies to the site as well.

Cheers

Author:  erlokovic [ Thu Feb 21, 2013 2:26 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

Hi pakeha_by,

i tried today your patch and my rendering went from 50 seconds to 9-10 seconds.. Thank you for your work!!

The table looks like the old one (but faster) and everything else seemed to be perfect too..

Thank you again!

Author:  andy_f [ Wed Apr 17, 2013 2:04 am ]
Post subject:  Re: Fast table rendering in MigraDoc

Andrew (pakeha_by) -

Thank you so much for your remarkable contribution. My render times went from the 8 to 10 minute range to about 15-20 seconds. This is for tables that end up spanning about 100 pages. Previously I was having trouble even getting the rendering to complete on smaller cloud instances, based upon the resources available. This is a huge improvement, and I have studied my results and can find no visible difference in the resulting tables being rendered. For whatever reason patch.exe would just give me a blank screen when run from the command line with the correct parameters, but I was able to successfully patch using TortoiseSVN and the patch file. It's disappointing that it has been two years since you've shared this significant contribution and even submitted it back for an upcoming release, yet it's still not part of the current release. In the absence of progress with the open source project, I'd encourage others to try this patch and hopefully someday it will be a part of the official release.

Author:  Thomas Hoevel [ Wed Apr 17, 2013 8:37 am ]
Post subject:  Re: Fast table rendering in MigraDoc

andy_f wrote:
It's disappointing that it has been two years since you've shared this significant contribution and even submitted it back for an upcoming release, yet it's still not part of the current release.
Nice that it works for you, but it is not fully compatible to the original implementation.
See here:
viewtopic.php?p=6852#p6852

We need an implementation that is 100% compatible.

Author:  romias [ Tue Oct 29, 2013 5:30 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

Now that KeepWith is fixed in pakeha patch (see http://forum.pdfsharp.net/viewtopic.php?p=6852#p7408)... do you think it is time to add it to the official release?

Or there are other issues with the patch?

I think it would be great to add this to the official release, to be added via Nuget and not requiring repatching in new official releases.

Thanks!!

Author:  Thomas Hoevel [ Wed Oct 30, 2013 9:17 am ]
Post subject:  Re: Fast table rendering in MigraDoc

romias wrote:
Now that KeepWith is fixed in pakeha patch do you think it is time to add it to the official release?
We need an implementation that is 100% compatible.
There was a problem with borders, there was a problem with KeepWith, there may be other problems. It won't be included without extensive QA. I am not the person to make that decision.

Author:  izaurek [ Tue Feb 18, 2014 4:16 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

Hi

I have found a bug.
If I make a cell which is 2 rows high (MergeDown=1) and the text has more than 2 lines, the text goes outside the cell.
In 2 cells right to the big cell I had texts with 1 line each.

It would be great if somebody could fix it :)

Pawel

Author:  Urieal [ Fri Sep 26, 2014 1:36 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

izaurek wrote:
Hi

I have found a bug.
If I make a cell which is 2 rows high (MergeDown=1) and the text has more than 2 lines, the text goes outside the cell.
In 2 cells right to the big cell I had texts with 1 line each.

It would be great if somebody could fix it :)

Pawel

I implemented the code and found this to be the case as well. I am not sure why. I'm very frustrated with the slow table rendering. I have to create a PDF that occasionally requires upwards of 50,000 rows (over about 315 pages). It took 2-3 hours to generate the file, which is just too long.

It took about 35 seconds with the new patch, but then it messes up my formatting on cells that are merged down :(.

Author:  pakeha_by [ Thu Oct 02, 2014 11:42 am ]
Post subject:  Re: Fast table rendering in MigraDoc

In case somebody still need fix for problem mentioned above (MergeDown = 1 with multiple lines):

File TableRenderer.cs, method TableRenderer.CreateNextBottomBorderPosition(), line 601:

instead of
Code:
foreach (Cell cell in this.mergedCells.GetCells(Math.Max(0, lastBorderRow), minMergedCell.Row.Index + minMergedCell.MergeDown))


must be (edited, I realize that previous fix won't work in some more complex circumstances)

Code:
      foreach (Cell cell in this.mergedCells.GetCells(Math.Max(0, this.mergedCells.GetFirstRowMergedWithRow(lastBorderRow))), minMergedCell.Row.Index + minMergedCell.MergeDown))


and add method GetFirstRowMergedWithRow() to MergedCellList class:

Code:
    public int GetFirstRowMergedWithRow(int row)
    {
        if (row == 0 || row >= this.RowCount)
            return row;

        var result = row;

        for (int colIndex = 0; colIndex < ColCount; colIndex++)
        {
            CellInfo cellInfo = CellInfos[row, colIndex];
            result = Math.Min(result, cellInfo.BlockRow);
            colIndex += cellInfo.Cell.MergeRight;
        }

        return result;
    }


Author:  Urieal [ Thu Oct 02, 2014 5:32 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

pakeha_by wrote:
In case somebody still need fix for problem mentioned above (MergeDown = 1 with multiple lines):

File TableRenderer.cs, method TableRenderer.CreateNextBottomBorderPosition(), line 601:

instead of
Code:
foreach (Cell cell in this.mergedCells.GetCells(Math.Max(0, lastBorderRow), minMergedCell.Row.Index + minMergedCell.MergeDown))


must be

Code:
      int startFromRow = lastBorderRow;
      while (startFromRow > 0 && (int)this.connectedRowsMap.GetByIndex(startFromRow - 1) == (int)this.connectedRowsMap.GetByIndex(lastBorderRow))
          startFromRow--;

      foreach (Cell cell in this.mergedCells.GetCells(Math.Max(0, startFromRow), minMergedCell.Row.Index + minMergedCell.MergeDown))


I can confirm that this last bit of code fixes any problems I've encountered thus far. My tables are rendering like lighting now :).

There is one caveat, which I am working on fixing.
If you change the borders of a cell during render time, after the MergedCellList.CellIndex has been populated, then the changes won't be rendered.
The "issue" (and I use the term lightly, because it is NOT an issue unless you are trying to change how tables render) stems from the MergedCellList.GetEffectiveBorders method.

The only reason I discovered this is due to my need to render a custom border on the last table row on each page. I can successfully update the cell borders, but when the cell is rendered it pulls border information.

I am currently overriding the Equals method for both the Borders and Border object, which will allow me to compare Borders information from CellInfo.Borders and Cell.Borders for equality. In the event they are not equal, the data from Cell.Borders can be copied over to CellInfo.Borders.

Well, that's the thought, anyway. :(

Author:  yellowmosquito [ Tue Oct 28, 2014 3:31 am ]
Post subject:  Re: Fast table rendering in MigraDoc

I have applied the fixes provided by Pekeha_by, as well as the latest code change he supplied to fix the "KeepWith" issue. The speed improvement is beyond dramatic! Thank you so much for putting this together for us.

I did come across one area where it appears that your code has limitations, so I thought I would share. I noticed that the code you supplied does not appear to work with styles. The result is an empty area.

This code does not work:
Code:
//make style to reference
Style style = document.Styles.AddStyle("Summary", "Normal");
style.Font.Size = 12;
style.ParagraphFormat.Shading.Color = colorGreen;

//create a paragraph of the above style
paragraph = section.AddParagraph();

paragraph.Style = "Summary";
paragraph.AddText("A bunch of text goes here n stuff");

I get a blank, colored box. However, no text appears inside of it.


Whereas this code would work:
Code:
//create a paragraph
paragraph = section.AddParagraph();

paragraph.Format.Font.Size = 12;
paragraph.Format.Shading.Color = colorGreen;
paragraph.AddText("A bunch of text goes here n stuff");

The text appears within the colored box as anticipated.


I don't know enough to claim that my code is 100% correct, but I do know the original (top) code was working with the official 1.32 assemblies. When I switched over to the Pekeha_by code (most recent), it stopped working as expected. The text throughout my documents basically disappeared.

I know this issue will have to be resolved in order for the code to be included in the next release of MigraDoc. As for myself, I am going through my code and removing all style references as we speak so that I can have correct rendering AND the blazing speed! This is working for me, so I hope this helps someone else.

Author:  pakeha_by [ Tue Oct 28, 2014 8:49 pm ]
Post subject:  Re: Fast table rendering in MigraDoc

yellowmosquito wrote:
This code does not work:



Works fine for me (see attachment):
Code:
            //make style to reference
            Style style = document.Styles.AddStyle("Summary", "Normal");
            style.Font.Size = 12;
            style.ParagraphFormat.Shading.Color = new Color(0, 255, 0);

            var section = document.AddSection();

            //create a paragraph of the above style
            var paragraph = section.AddParagraph();

            paragraph.Style = "Summary";
            paragraph.AddText("A bunch of green text goes here n stuff");

            paragraph = section.AddParagraph();
            paragraph.AddText("A bunch of regular text goes here n stuff");



Attachments:
para.png
para.png [ 6.73 KiB | Viewed 8077755 times ]

Author:  Thomas Hoevel [ Wed Oct 29, 2014 8:40 am ]
Post subject:  Re: Fast table rendering in MigraDoc

pakeha_by wrote:
Works fine for me
Your paragraphs are not in a table. Does it still work with a table around the paragraphs?

Author:  pakeha_by [ Wed Oct 29, 2014 9:19 am ]
Post subject:  Re: Fast table rendering in MigraDoc

Thomas Hoevel wrote:
Your paragraphs are not in a table. Does it still work with a table around the paragraphs?


Yep
Code:
            var section = document.AddSection();
            var table = section.AddTable();

            var col = table.AddColumn();
            var row = table.AddRow();
            var cell = row.Cells[0];
            cell.Borders.Style = BorderStyle.Single;

            //create a paragraph of the above style
            var paragraph = cell.AddParagraph();

            paragraph.Style = "Summary";
            paragraph.AddText("A bunch of green text goes here");

            paragraph = cell.AddParagraph();
            paragraph.AddText("A bunch of regular text goes here");


Attachments:
style2.png
style2.png [ 6.45 KiB | Viewed 8077739 times ]

Page 1 of 2 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/