I am trying to export records from database into pdf using itext pdf library in java..But i am getting following problems in alignment of pdf table inside pdf file..
1.Table is not showing in the full pdf page .It is leaving spaces from left and right of the pdf page.
2.Every page is showing values in half of the page only .Means pdf table is showing in half of the pdf pages..
Here is my code..
Document document = new Document();
PdfWriter.getInstance(document, fos);
PdfPTable table = new PdfPTable(10);
table.setWidthPercentage(100);
table.setSpacingBefore(0f);
table.setSpacingAfter(0f);
PdfPCell cell = new PdfPCell(new Paragraph("DateRange"));
cell.setColspan(10);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setPadding(5.0f);
cell.setBackgroundColor(new BaseColor(140, 221, 8));
table.addCell(cell);
table.addCell("Calldate");
table.addCell("Calltime");
table.addCell("Source");
table.addCell("DialedNo");
table.addCell("Extension");
table.addCell("Trunk");
table.addCell("Duration");
table.addCell("Calltype");
table.addCell("Callcost");
table.addCell("Site");
while (rs.next()) {
table.addCell(rs.getString("date"));
table.addCell(rs.getString("time"));
table.addCell(rs.getString("source"));
table.addCell(rs.getString("destination"));
table.addCell(rs.getString("extension"));
table.addCell(rs.getString("trunk"));
table.addCell(rs.getString("dur"));
table.addCell(rs.getString("toc"));
table.addCell(rs.getString("callcost"));
table.addCell(rs.getString("Site"));
}
table.setSpacingBefore(5.0f); // Space Before table starts, like margin-top in CSS
table.setSpacingAfter(5.0f); // Space After table starts, like margin-Bottom in CSS
document.open();//PDF document opened........
document.add(Chunk.NEWLINE); //Something like in HTML :-)
document.add(new Paragraph("TechsoftTechnologies.com"));
document.add(new Paragraph("Document Generated On - " + new Date().toString()));
document.add(table);
document.add(Chunk.NEWLINE); //Something like in HTML :-)
document.newPage(); //Opened new page
//In the new page we are going to add list
document.close();
fos.close();