cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

How to print table to pdf using one list?

WM_9965332
11-Garnet

How to print table to pdf using one list?

I have two lists of dynamic sizes containing child part numbers (first level BOM) of a part and its predecessor.  I would like to print on pdf in the format of a table as shown below;

 

list 1

list 2

1003

1000

1002

1002

1004

 

1005

 

 

The function I am using retrieves one list and populates the already created table using that list (itextPDF.PDFcell) See code snippets below;

PdfPTable table = new PdfPTable(2);
table.setSpacingBefore(8);
table.setWidthPercentage(80f);

insertCell(table, list1, Element.ALIGN_CENTER, 1, fa); // insert 1st  column
insertCell(table, list2, Element.ALIGN_CENTER, 1, fa); // insert 2nd column
table.setHeaderRows(1);

for (String value : list) {
insertCellAll(table, value, fa); //insert rows
}

 

public static void insertCellAll(PdfPTable table, String text, Font fa) {
// create a new cell with the specified Text and Font
PdfPCell cell = new PdfPCell(new Phrase(text.trim(), fa));
if (text.trim().equalsIgnoreCase("")) {
cell.setMinimumHeight(10f);
}
// add the call to the table
table.addCell(cell);
}

 

How do I concatenate both lists to allow me solve this problem and is there another way to go about printing tables using lists with dynamic values?

0 REPLIES 0
Top Tags