Thanks for taking the time to answer my question. I'm dynamically filling data in a PDF template. Everything is working as expected except for one part. The table I am generating in Java code is not displayed in the PDF. My question would be how do I position a table in the top left corner using iText's API?
This is my code so far:
PdfPTable table = new PdfPTable(3);
PdfPCell cell = new PdfPCell(new Phrase("VAT Rate"));
table.setWidthPercentage(500);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Net Value"));
table.addCell(cell);
table.addCell("VAT Amount");
table.addCell(Double.toString(currentVatRate));
table.addCell(Double.toString(currentVatRateNetValue));
table.addCell(Double.toString(currentVatVatAmount));
table.addCell("Totals");
table.addCell(Double.toString(subTotalExcludingVat));
table.addCell(Double.toString(totalVatAmount));
Basically I need a 3 column table, each column 33%. How do I set the tables position?
Try this:
// table.setWidthPercentage( 500 );
table.setWidths( new int[]{ 1, 1, 1 } );
You should be using something like the following code:
com.itextpdf.text.Document document =
new com.itextpdf.text.Document( com.itextpdf.text.PageSize.A4 );
FileOutputStream fos = new FileOutputStream( outputFileFolder + "PdfTableExample.pdf" );
com.itextpdf.text.pdf.PdfWriter pdfWriter =
com.itextpdf.text.pdf.PdfWriter.getInstance( document, fos );
document.open();
document.add( table );
document.close();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.