Reputation: 13
This is my code
// Create table for seller and buyer information
Table table = new Table(UnitValue.createPercentArray(new float[]{50, 50}));
table.setWidth(UnitValue.createPercentValue(100));
// Add seller and buyer information
table.addCell(new Cell().add(new Paragraph("Seller:")).setBorder(Border.NO_BORDER).setPadding(5).setBorderRight(new SolidBorder(1)));
table.addCell(new Cell().add(new Paragraph("Buyer:")).setBorder(Border.NO_BORDER).setPadding(5).setBorder(Border.NO_BORDER).setBorderLeft(new SolidBorder(1)));
table.addCell(new Cell().add(new Paragraph("XYZ Pvt. Ltd.\nNew Delhi, India\nGSTIN: 29AABBCCDD121ZD")).setBorder(Border.NO_BORDER).setPadding(5).setBorderRight(new SolidBorder(1)));
table.addCell(new Cell().add(new Paragraph("Vedant Computers\nNew Delhi, India\nGSTIN: 29AABBCCDD131ZD")).setBorder(Border.NO_BORDER).setPadding(5).setBorder(Border.NO_BORDER).setBorderLeft(new SolidBorder(1)));
// Add vertical line between columns
table.addCell(new Cell().setBorder(Border.NO_BORDER));
table.setBorder(new SolidBorder(1));
// Add the seller and buyer information table to the document
document.add(table);
// Add items information
Table itemsTable = new Table(UnitValue.createPercentArray(new float[]{25, 25, 25, 25}));
itemsTable.setWidth(UnitValue.createPercentValue(100));
itemsTable.setBorder(new SolidBorder(1));
// Add table headers
itemsTable.addCell(new Paragraph("Item").setTextAlignment(TextAlignment.CENTER));
itemsTable.addCell(new Paragraph("Quantity").setTextAlignment(TextAlignment.CENTER));
itemsTable.addCell(new Paragraph("Rate").setTextAlignment(TextAlignment.CENTER));
itemsTable.addCell(new Paragraph("Amount").setTextAlignment(TextAlignment.CENTER));
// Add table data
itemsTable.addCell("Product 1");
itemsTable.setTextAlignment(TextAlignment.CENTER);
itemsTable.addCell("12 Nos");
itemsTable.setTextAlignment(TextAlignment.CENTER);
itemsTable.addCell("123.00");
itemsTable.setTextAlignment(TextAlignment.CENTER);
itemsTable.addCell("1476.00");
itemsTable.setTextAlignment(TextAlignment.CENTER);
document.add(itemsTable);
enter image description here The above image is the pdf generated which has the invoice. The live does not touch the border. Can someone please help? I tried everything but nothing helped.
Upvotes: 0
Views: 38