Reputation: 983
Is it possible to repeat table header if part of a table is forwarded to the next page in itext. Xml workerhelper used for create pdf from html string.Some times my html string have large table of content the content forwarded to next page. the i need to add table header in the nextpage and continue to table of content.please see this image for more clarity.
Now following code used for creating pdf.
document.open();
try{
XMLWorkerHelper.getInstance().parseXHtml(writer,
document, new ByteArrayInputStream(parserXHtml(page.getPageContent()).getBytes()));
writer.setPageEvent(orientation);
}catch(Exception e){
logger.error("Error:invalid html content detected!!");
}
document.close();
Is it possible in itextpdf Api-5.5.11. If we are using table we can repeat table like this.
PdfPTable table = new PdfPTable(2);
// header row:
table.addCell("Header");
table.addCell("Header Value");
table.setHeaderRows(1);
// many data rows:
for (int i = 1; i < 51; i++) {
table.addCell("key: " + i);
table.addCell("value: " + i);
}
I need to know it is possible in xmlworkerhelper.
Upvotes: 2
Views: 3366
Reputation: 4588
iText 7.2.5: use addHeaderCell(... );
You even may want to have the first header row different than the repeating ones: Use setSkipFirstHeader to true, and add the first header row with the usual addCell(...):
This is a one column table that repeats the header row on each page, but has a different header for first occurence (if you have more than one column, just repeat the addHeaderCell resp. addCell accordingly):
String title = ....;
table.setSkipFirstHeader( true );
var titleCell = new Cell( title + " (continued)" );
// repeat the header on each new page (but not the first one):
table.addHeaderCell( titleCell );
var firstTitleCell = new Cell( title );
table.addCell( firstTitleCell );
I recommend also to call setKeepTogether( true ) in order to not split the first header row from the body.
Upvotes: 0
Reputation: 157
Just set
style="repeat-header: yes; repeat-footer: yes;"
for your table. Then it will repeat header and footer for all pages until the table end.
Upvotes: 2