I am using itextsharp to create pdf file from html. I have a dynamic string that will occupy half to full page and a dynamic table after that. The problem is there is lot of space if i move the whole table to a new page sometimes and if i break the table the header alone is in one page and the rest of the content is in the next page sometimes.
I want to know if it is possible to make sure that the page break is not introduced between the table header and the first row of the table.
I am aware of how to do the following
Prevent the whole table from splitting if there is not enough space in the page and move it to a new page by using
KeepTogether = true
Allow the table to split but prevent the row from splitting if there is not enough space by using
KeepTogether = false;
SplitRows = true;
SplitLate = true;
Repeat the table header if the table spans across multiple pages
But i don't want any of these methods. I want to allow the table to split but just not between the header and the first row or the first two rows otherwise.
Solution figured out: Used KeepRowsTogether()
Related
I am displaying data, using two nested tables in order to put the text in the middle of the category.
The "Fonction" is in the detail band, with a table displaying the "Modele" values. To put these values in the middle I put a second table in the first one, to print "Ligne", "Taille"...
"Modele" can gather multiple "Ligne", which can be gathered by "Fonction":
This is working fine, until a three lines table reaches the end of page. There, it does not split, and is diplayed on the next page :
How can I split this table to prevent getting a blank line?
I managed to get this working by using a crosstab with row groups for the first three columns, and the other fields are put in the detail box
You must put these fields into mesures to be able to use them in the crosstab.
I have a dynamic table that will occupy half to full page and a dynamic table after that. The problem is there is lot of space if i move the whole table to a new page sometimes and if i break the table the header alone is in one page and the rest of the content is in the next page sometimes.
I want to know if it is possible to make sure that the page break is not introduced between the table header and the first row of the table.
I am aware of how to do the following,
Prevent the whole table from splitting if there is not enough space in the page and move it to a new page by using
KeepTogether = true
Allow the table to split but prevent the row from splitting if there is not enough space by using
KeepTogether = false;
SplitRows = true;
SplitLate = true;
Repeat the table header if the table spans across multiple pages
But i don't want any of these methods. I want to allow the table to split but just not between the header and the first row or the first two rows otherwise. Please any one give some idea to sort out this issue.
Samplepdf:
I had search some relative question which had been asked, but seem not too much my condition.
My problem is simpler to this problem
Table in iTextSharp is not page breaking as desired?
The different between my problem and his is I need header in each extend page.
Currently I put a long table in one of cell, it make me has header in each page, but if the table to long, all table will shift to second page, and first page is empty.
I have tried table.KeepRowsTogether, but the 15 rows stay in second page and rest in third..
I determine what is the length of list. if number of items more than 15 then I separate list into 0 ~ 14 and 15th to the end, keep all content in the same table then there will having header in second page. Case close
I'm building a pdfptable thru ItextSharp, but I need to know, while I'm adding cells, my Y position in the page. Cells have a variable height.
I need to know it to avoid tu put a new 'Breaking title' in the table if this would go on the last table row, as it should go on a new page (on cust request).
I tried writer.getverticalPosition() but it seems not reliable in composing a table.
Is there a way to know it ?
There's a contradiction in your question. Let me explain what doesn't make sense.
You create a PdfPTable, let say you have an object named table. when you add cells to table, the object grows. Plenty of data is stored into memory.
Now you say: I want to know the Y position of the rows on the page while I'm adding cells.
Which page? There may not even be a page? As long as you build the table object, there is no page, there are no Y positions. One table could be 200pt heigh when added to a page with a width of 400pt. The same table could be 400pt heigh when added to a page with a width of 200pt. It isn't until you add the table object to a Document that the table gets its shape.
If you want to make sure a "title" isn't the last row on a page, you should break up your table in smaller parts. Create a subtable and add it to the document. Now use getVerticalPosition() and check how much space is left. If there isn't sufficient space for the first X rows of the next subtable, move to a newPage() and add the next table there, otherwise add the table on the current page.
If you define the widths correctly, nobody will see that you've been adding more than one table: it will look as if you added one large table instead of different small ones. If you don't know how to calculate the height of the rows in the subtables, please note that you need to define the total width of the table and lock the widths. For the reason explaiined above, no software can calculate the height of a table if it doesn't have any info about its width.
I am creating an invoice using the iTextSharp. That displays nicely but sometime, when invoice items are larger in qty, the summary portion (which displays subtotal, tax, discounts, grand total etc) is splitted. Some displayes in current page and some moves to next page. I was thinking to move entire summary portion into next page, if current height left is not enough for that.
However, to do that, I need to know that how much page height is left (after my current page content rendering). I wonder if someone know how to calculate current left height of the page? OR if there is a property in the pdfPTable which may force the table to print itself as a whole and dont let it split across multiple pages! I guess if second option is available, it will be easy.
In summary, I need to know if it is possible to calculate remaining page height, and also if that is possible to force a table to NOT split across multiple pages.
thank you.
Sameers
You can set SplitLate to false to avoid auto page break in a cell data exceeds limit.
......
table.addCell(cellData);
table.SplitLate = false;
......
I suggest you use a nested table for your summary section. I don't believe iText will split a given cell on a page boundary, so everything in that cell (even if its a nested table with cells of its own) will stay on the same page.
Use the table's cell's row span so it takes up an entire row on its own.
I'm not certain, but I'd wager a beer on it.
What object are you using to add your data to the PDF? MultiColumnText, Paragraph, Phrase?
You should be able to use Document.PageSize.Height property to return the height of the Page.
Then use PDFPTable.Height to return the height of your table.
So just use the logic Document.PageSize.Height - table.Height, and you'll have the remaining y-axis space available.
The PDFPTable object has properties named SplitLate and SplitRows. I believe you can use these properties to try and keep the table on one page.