Repeat PdfPTable header in all the continuation pages using iText - java

How can I repeat the headings of a PdfPTable in all the pages if the length of the table exceeds one page?

Look at setHeaderRows(int headerRows) of PdfPTable. Rows defined there as a header should persist on new pages.
table.setHeaderRows(1)
for the first row as a header.
See the API.

Related

Prevent merge cell to split across pages

I have generated an Excel document with jxls and POI. Now POI has merged cell, half data is in page 1 & other half of merged cell in page 2. How can I prevent it?
Unfortunately you can't. That's a disadvantage of Excel. Excel does not provide a "keep merged cells on one page" feature. One need to set an explicit page break above of the row which shall the first on the new page.
Apache POI provides Sheet.setRowBreak to do so.
So you need to know what row is the first one having the merged cells split into two pages. Then set row break to the row above.
For example if first row index of the rows having the merged cells split into two pages is 25, then:
...
Sheet sheet ...
...
sheet.setRowBreak(24);
...
Of course this only can be used if the row positions on the page are static or if one knows how many rows fit to one page. I don't know any more dynamic solution.
Same is if merged columns split over two pages. Then manually set a column break is needed.
Apache POI provides Sheet.setColumnBreak to do so.
Of course this has same disadvantages as manually row break has.

iText PDF template dynamic row insertion on tables

I have a requirement where I need to generate a PDF document in Java using iText.
The ask is to use a PDF template, and inject the data values in a user designed PDF template to produce the desired output PDF.
The documentation on the iText site is not clear/or I didnt search them completely, so asking for support or article regarding this,
Our use case is to generate a table from a PDF template, where the number of rows is determined by the data (i.e. in here JSON). I should be able to dynamically scale the number of rows in a PDF template based on the data size.
Is this possible?
I was referring to this article:
https://github.com/koendehaen/itext_summit_pdf_templates
In the above GITHUB example, the rows were prepopulated in the PDF template, I want something like the below screenshot, similar to how Handlebars provide, where a for loop on a hbs template, and I can inject data.
Example:
Suppose I have a table like below
But here the row count is dynamic based on data set, how to scale the table dynamically
Note:
I cant create the template in HTML, like handlebars, etc...
Since business people with little to no technical background will be the users who will be generating the PDF template.
You can search the all key values of your JSON, and before insert this value in PdFTable. In my case, i get the lastCellNum:
Row row = rowIterator.next();
PdfPTable table = new PdfPTable(row.getLastCellNum());
Iterator<Cell> cellRow = row.iterator();
while(cellRow.hasNext()) {
Cell cell = cellRow.next();

Show pdf table header only for first table on a page

I have PDF document generated by iText in Java application, where I have a lot of tables with the same columns. In order to save some space in document I would like to have header only the first table on page. Any ideas? Thanks.

Setting Header Row in Itext Table

I am creating a table using itext. Now while setting header row, if I set table.setheaderrows(2) then it sets first 2 rows as the header. But in my case I want only row no. 2 (not row number 1) to be reprinted while table is extended on the next page.
Is there any way to achieve this?
If you only work with a single PdfPTable, you can't define the second row as the header row that needs to be repeated. The trick is to use two PdfPTable instances with the same widths for the columns. The first one would be a single row table for the first header row, the second one would start with the header row that needs to be repeated. If you add two tables to a document, one right after the other, they are glued to each other and nobody will notice that it's not a single table.

Itext PDF table cell's data is not coming on second page

I am using pdfptable to print. Cell, when table is reaching at end of page and any cell which is carrying more data and with same cell continuation is not coming next page , actually it is truncating data of cell . I am using single table in my code to print data
Does it possible to solve this issue?

Categories