I would like to know if there is a way to detect if the last row in a table is exceeded the page and if so write it on the next page and write the table header to the next page as well.
I don't want to use table.KeepTogether = true; because if the table is longer than 1 page it just move the exceeded rows to the next page without the header.
The table does not start from the beginning of the page, so using the onStartPage() event is not good.
This is how it looks when the table is exceeded 1 page:
Hope that someone can help me here.
Thanks!
Seems like you want the repeating header functionality as described in the HeaderFooter1 example. For the corresponding C# examples, see http://tinyurl.com/itextsharpIIA2C04
For instance, if table is an instance of the PdfPTable class and the first row needs to be repeated when the table is split in two, then you need to add this line:
table.HeaderRows = 1;
Now the first row will be repeated automatically.
Related
The rows are dynamic I want new page after every 3 rows.
I tried
table.SplitLate = false;
but It won't work please help me out.
The easiest way to enforce a page break in a table is to actually create multiple PdfPTable objects, a separate one for the content destined for each page, and by turns add one of these objects to the Document and call NewPage.
In case of the OP's task he should begin a new table after three rows and call NewPage in-between adding these table objects.
I am trying to do something like this but I don't know how:
I have a table in c# which I increase and decrease during runtime.
Each row contains data, that is being parsed from an object.
I want to get an access to the object that the line is parsing, some a pseudo of it would be:
if (table.row.object == selectedObject)
I can't do it from the row number or something because the rows are being removed and inserted, each time with different objects.
any ideas, please?
EDIT: I am using TableLayoutPanel to work with a table, and this is how I add rows and removes them:
I am adding rows to the table dynamically, I have set of buttons and when I click one it deletes all old rows from the table and adds new rows that are related to this button.
This is the way I add new rows:
tlp.RowCount++;
tlp.RowStyles.Add(new RowStyle(SizeType.AutoSize));
tlp.Controls.Add(new Label() { ... }, cellIDX, rowIDX);
// adding more columns //
and to remove old rows I loop through all rows from bottom to top, removes all related controls of the current cell, then I remove style and row num like so:
tlp.RowStyle.RemoveAt(rowNum);
tlp.RowCount--;
thank you
you can also see a previous question I had related to this subject:
C# change table row color when mouse hover
You can try having a new column in the table (call it original_row_no) and set the row values into that, before you start your insertion/deletion process. That way you can reference the row directly (this is in response to your final line which says "I can't do it from the row number or something because the rows are being removed and inserted, each time with different objects."
A better way is to have a unique id in the table and run your references against that.
It is much more easier to help if you show the code you are trying.
Is there any way to catch a break in the table in order to insert a "Continued on next page" row? I've tried checking each row to see if the HeaderFormat is -1 (as I set headers to repeat on subsequent pages), but that doesn't work. I suppose I could count rows and guestimate, but I'd rather have an exact point at which to insert the new row at the bottom of the table before it breaks onto another page.
I found a solution. This post describes how to find the page number from a range. You can call this with the range of a row and check when the page changes. When the page changes go back a row index and add the "Continued..." text.
I'm creating a PDF document using iTextSharp. I see how to create a new table with a number of columns but I can't see anyway to dynamically add a new column. The problem I have is I'm not going to know the number of columns I need straight away, so need to keep adding them
Can somebody please enlighten me or am I going to have to re-create the table each time I need to add a column?
Thanks
Mat
Wouldn't it then make sense to create an intermediate model which contains the table you want, and is capable of then creating the PDF table for you?
I know it sounds like a lot of work, but in the long run it should help in that you would be able to dynamically alter the rows and columns as you build them, and then at the end, simply "compile" the table and spit out the PdfPTable object?
PdfPTable tables are immutable as far as column count goes once created.
The only workaround I can think of is to start with a Whole Bunch of columns and... nope that won't work either. You cannot even add cells to an existing row. I was thinking you could play around with the column spanning to mask your extra columns and adjust them as you added more cells to the rows, but that won't work either.
You must rebuild the table when adding columns. No way around it.
I strongly recommend you figure out how to determine your column count before creating the table in the first place... even if you have to "dry run" through your data. Use some intermediate format (String[][] or whatever) to keep your data, then build the table from that, not the data as it comes to you. Or at least track how many columns you'll need.
Given a huge amount of data, a single pass may not be practical/possible. But rebuilding your whole table several times can't be much better. That's really a performance tuning question that only you have the information to answer.
ITextSharp tables work in a different way to HTML tables (which I guess you're used to).
All you need to tell it is the number of columns you have and then keep adding cells.
Say you create a pdfptable with 5 columns. The 5th cell you add will be on the first row and the 6th cell will be in the 1st column on your 2nd row.
The only downside to this is if you need to add rows where not all the cells are populated but I usually get around this by just adding an empty cell or a cell with a space in it.
I am building a table that spans multiple pages of my PDF. I would like the column header of the table to appear as the first row on each page. Is there some way that I can detect when the page is breaking and insert the column headers rather than the next data row?
Check the iTextSharp tutorial on SourceForge, chapter 5, section "Large Tables," example 10.
You basically call EndHeaders() on your Table.