I'm new in java and I use itextpdf as my output.
Right now I am so flustered by this problem.
My problem is that I want to display the resultset from the database in pdf format with a twist.
for example, i will set a table with 3 columns,
and these are the resultset from the database,
Name
John
Jane
Mary
Sonny
Kiel
so now the output in itextpdf should be viewed like this
|__ columnname _|__ columnname_|_columnname__|
|_____John______|_____Jane_____|_____Mary____|
|_____Sonny_____|_____Kiel_____|_____________|
I want the results to be inserted in every column and i don't have any idea how to do this.
anyone? it would be nice if someone can guide me.
Document document = new Document(PageSize.A4, 25, 25, 25, 25);
PdfWriter writer = PdfWriter.getInstance(document,new FileOutputStream("D:\\PURCHASEORDER\\"+see+".pdf"));
document.open();
try {
Class.forName(driver);
conn = DriverManager.getConnection(url+db, user, pass);
Statement st = conn.createStatement();
String zero = dates.getSelectedItem().toString();
String sql = "select name as hehe from names where servedate = '"+zero+"'";
pst=conn.prepareStatement(sql);
rs=pst.executeQuery();
Rectangle react = writer.getPageSize();
PdfPTable table2 = new PdfPTable(new float[] { 3,3,3});
table2.setTotalWidth(527);
table2.getDefaultCell().setBorder(Rectangle.NO_BORDER);
PdfPCell cell = new PdfPCell(new Paragraph(""));
cell.setColspan(8);
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setBackgroundColor(BaseColor.GRAY);
table2.addCell(cell);
table2.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
while(rs.next()){
String v1 = rs.getString("hehe");
FontFactory.getFont(FontFactory.TIMES_BOLD,14,BaseColor.BLACK)));
table2.addCell(new Paragraph("TOTAL Number: "+v1+"", FontFactory.getFont(FontFactory.TIMES_ROMAN,12,BaseColor.BLACK)));
table2.addCell(new Paragraph("TOTAL Number: "+v1+"", FontFactory.getFont(FontFactory.TIMES_ROMAN,12,BaseColor.BLACK)));
table2.addCell(new Paragraph("TOTAL Number: "+v1+"", FontFactory.getFont(FontFactory.TIMES_ROMAN,12,BaseColor.BLACK)));
}
table2.setWidthPercentage(100);
document.add(table2);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
document.close();
String pdfFile="D:\\PURCHASEORDER\\"+see+".pdf";
File f = new File(pdfFile);
if (pdfFile.toString().endsWith(".pdf")) {
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + pdfFile);
} else {
//For cross platform use
Desktop desktop = Desktop.getDesktop();
desktop.open(f);
}