Keep table in one piece MigraDoc / PDFsharp - c#

I am using PDFsharp / MigraDoc to write tables and charts to PDF files. This worked great so far, however MigraDoc will always split my tables (vertically) when it should move the whole table to the next page in the document. How do I make sure the table will stay in one piece?
Table class of MigraDoc.DocumentObjectModel.Tables has a bool KeepTogether property however it seems to have no effect (either set to true or false).
Is there a way to do it manually? Is there any way to "measure" the distance from the end of the page and compare it to tables height? (Or any other way of knowing wether the table will be split or not)
Please note that I am using PDFsharp / MigraDoc for the first time. If there are any best practices I ought to know, please let me know. If there are some good examples out there (I saw those on PDFSharp's home page, but that's about it) I'd love to know about them!

You can set the KeepWith property of a Table Row to specify blocks that must be kept together.
If you know the table fits on one page, you can set the KeepWith property of the first row to (table.Rows.Count - 1) when the table is finished.

Related

Do Not Page Break on Table in Aspose PDF?

I am trying to stop Aspose PDF from Page Breaking in the middle of my table (C# .NET). We dynamically add information to this PDF, but this table will always be two rows.
I have found the table.isBroken attribute always returns true and row.isRowBroken always returns false (from Aspose). This does not help me to stop the page from breaking in the middle of this table.
I have also tried adjusting the margin to no avail since our pages are dynamic. Google and the Aspose forums and documentation have revealed nothing. I have turned to asking a question here on stackoverflow.com.
Any ideas or suggestions would be helpful! Thank you so much for your time!
You may use RepeatingRowCount property of Table class to set header rows count. It will keep these rows together on page break.
I'm Tilal,developer evangelist at Aspose.
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
table.RepeatingRowsCount = 2;

rdlc - Concatenate 2 tablix - same dataset - synchronization lost..,

Since i haven't find a way to merge colunms cells in rdlc, I've tried to concatenate 2 tablixes horizontaly- one is "standard" table, and the other is one field (those were my needs).
Running my sp on my rdlc, it works fine where there is one record to display.
However, when the result is multiple records, and I'm saving results in .pdf file, the 2 tables are not "synchronized" together any more - the gaps between results of each records are different.
I've tried to surrender the tablixes in rectangle and define a page break after rectangle - table still not synchronized...
Please advice..... ☺
Combine your two tablix into one. You can create the appearance of having two by putting an empty column between the two "sides" with no borders on top or bottom of the cells. It will look like two tables side by side, even though it is one table, and the rows will be forced to line up horizontally.
Another possibility for you is to have a sub-report. Create a simple report of just the tablix of the second table in question of the field(s) you want to include.
Then edit your primary report to include the sub-report. I cant direct in detail now how to link-up the sub reports and parameter link them, but suggest some reading up on it. So Each detail row in the parent report would be a group by (its PKID for example), then add the sub-report to it. This way as many rows at the sub-level go if 1 or more...

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

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

How do you programmatically break up one Excel document into several while still maintaining each cell's style and format?

m trying to break one large Excel spreadsheet into several. I've made good progress, but I'm running into some problems. Specifically, the values that get copied over don't retain their format (for instance, 40322 instead of 5/24/2010 and -101 instead of (101.00) ). I've tried using the style (see below) but that doesn't even get me the font, let alone the number format. Any help or a poke in the right direction would be appreciated.
There are 2 loops, one for row, one for column.
destinationSheet.Cells[i, j].Style = sourceSheet.Cells[i, j].Style;
Instead of looping for each cell, you can copy/paste the entire range of cells using the pastespecial method.
http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.namedrange.pastespecial(VS.80).aspx

Cleanest way to implement collapsable entries in a table generated via asp:Repeater?

Before anyone suggests scrapping the table tags altogether, I'm just modifying this part of a very large system, so it really wouldn't be wise for me to revise the table structure (the app is filled with similar tables).
This is a webapp in C# .NET - data comes in from a webservice and is displayed onscreen in a table. The table's rows are generated with asp:Repeaters, so that the rows alternate colers nicely. The table previously held one item of data per row. Now, essentially, the table has sub-headers... The first row is the date, the second row shows a line of data, and all the next rows are data rows until data of a new date comes in, in which case there will be another sub-header row.
At first I thought I could cheat a little and do this pretty easily to keep the current repeater structure- I just need to feed some cells the empty string so that no data appears in them. Now, however, we're considering one of those +/- collapsers next to each date, so that they can collapse all the data. My mind immediately went to hiding rows when a button is pressed... but I don't know how to hide rows from the code behind unless the row has a unique id, and I'm not sure if you can do that with repeaters.
I hope I've expressed the problem well. I'm sure I'll find a way TBH but I just saw this site on slashdot and thought I'd give it a whirl :)
When you build the row in the databinding event, you can add in a unique identifier using say the id of the data field or something else that you use to make it unique.
Then you could use a client side method to expand collapse if you want to fill it with data in the beginning, toggling the style.display setting in Javascript for the table row element.
just wrap the contents of the item template in an asp:Panel, then you have you have a unique id. Then throw in some jquery for some spice ;)
edit: just noticed that you are using a table. put the id on the row. then toggle it.

Categories

Resources