Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine if a MigraDoc table would be split among two pages?

Tags:

c#

migradoc

I'm using MigraDoc to generate some PDFs. I have code to create a table of text for each element in an array and am printing out pages with these tables.

However, the requirements I am being given is that if I have 2 tables, and the 2nd table would not fit on the page due to the length of the first table, I need the 2nd table to start the next page. I then need to repeat this for each table I am adding to my document.

How would I go about doing this?

like image 772
KallDrexx Avatar asked Oct 15 '12 20:10

KallDrexx


1 Answers

If all tables are small enough to fit a single page, then there is a simple solution: set the KeepWith property of the first row to row count minus one to keep the whole table on one page.

If tables do not always fit a single page: you could try a hack, e.g. setting KeepWith to 6 or 8 or 10 (depends on the height of your table rows). If the value is close to what fits on a single page (without going over), tables will start on a new page automatically.
Obviously this will work very good if table rows have a constant height; if tables rows have varying heights, this will not work reliably, but will still prevent tables that will only have one or two rows on the first page (this is not your requirement, but maybe the requirement can be discussed?).

The clean (but complicated) way to fulfill your requirements: get access to the internal GetRenderInfoFromPage method. You will have to start an incremental process:
1) render the document;
2) if you find a split table, insert a page break before that table and repeat from 1.
See also here:
http://forum.pdfsharp.net/viewtopic.php?p=1960#p1960

like image 107
I liked the old Stack Overflow Avatar answered Sep 22 '22 01:09

I liked the old Stack Overflow