Question

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

Was it helpful?

Solution

You can set SplitLate to false to avoid auto page break in a cell data exceeds limit.

......
table.addCell(cellData);

table.SplitLate = false;
......

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top