1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
if (jRadioButton2.isSelected()) {
Object date = jTextField1.getText();
Paragraph paragraph = new Paragraph();
Document document = new Document(PageSize.A4);
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
java.util.Date utilDate = sdf.parse(date);
java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
try {
PdfWriter.getInstance(document, new FileOutputStream("Test.pdf"));
document.open();
Chunk chunk = new Chunk("Synthèse",
FontFactory.getFont(FontFactory.COURIER, 18, Font.NORMAL, Color.WHITE));
chunk.setBackground(Color.GRAY);
document.add(chunk);
//Tableau 1
Table tableau = new Table(3, 2);
tableau.setBorderColor(Color.white);
tableau.setPadding(3);
tableau.setWidth(100);
try {
stmt = (PreparedStatement) con.prepareStatement("SELECT No, Date, Obs, Lieu, Details, id_auteur FROM t_films WHERE Date = '" + date + "'");
stmt.setDate(1, date);avec un objet Date
rs = stmt.executeQuery();
while (rs.next()) {
String id = rs.getString(6);
//JOUR
paragraph = new Paragraph(rs.getString(2),
new Font(Font.BOLD, 14, Font.BOLD, Color.BLACK));
paragraph.setIndentationLeft(210f);
document.add(paragraph);
//Tableau 1
Cell cell = new Cell(new Paragraph(rs.getString(3),
new Font(Font.BOLD, 12, Font.BOLD, Color.BLACK)));
cell.setBorderColor(Color.white);
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
tableau.addCell(cell);
cell = new Cell("");
cell.setBorderColor(Color.white);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
tableau.addCell(cell);
cell = new Cell(new Paragraph("N° : " + rs.getString(1),
new Font(Font.BOLD, 12, Font.BOLD, Color.BLACK)));
cell.setBorderColor(Color.white);
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
tableau.addCell(cell);
cell = new Cell(new Paragraph(rs.getString(2),
new Font(Font.BOLD, 10, Font.BOLD, Color.BLACK)));
cell.setBorderColor(Color.black);
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
tableau.addCell(cell);
cell = new Cell(new Paragraph(rs.getString(3),
new Font(Font.BOLD, 10, Font.BOLD, Color.BLACK)));
cell.setBorderColor(Color.black);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
tableau.addCell(cell);
cell = new Cell(new Paragraph(rs.getString(6),
new Font(Font.BOLD, 10, Font.BOLD, Color.BLACK)));
cell.setBorderColor(Color.black);
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
tableau.addCell(cell);
document.add(tableau);
document.add(Chunk.NEWLINE);
paragraph = new Paragraph(rs.getString(4),
new Font(Font.BOLD, 11, Font.BOLD, Color.BLACK));
paragraph.setIndentationRight(20f);
document.add(paragraph);
paragraph = new Paragraph(rs.getString(5),
new Font(Font.NORMAL, 11, Font.BOLD, Color.BLACK));
paragraph.setIndentationLeft(20f);
document.add(paragraph);
paragraph = new Paragraph(rs.getString(5),
new Font(Font.NORMAL, 11, Font.NORMAL, Color.BLACK));
paragraph.setIndentationRight(20f);
document.add(paragraph);
}
} catch (Exception e) {
System.out.println("Erreur");
}
}
} catch (Exception e) {
System.out.println("Erreur");
}
document.close();
//Execute le PDF
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec(new String[] // 2 parametres pris dans un tableau, l'appli et le pdf
{
"C:\\Program Files\\Adobe\\Reader 9.0\\Reader\\AcroRd32.exe",
"F:\\Projet\\NetBeansProjects\\Films\\Test.pdf"});
} catch (Exception e) {
System.out.println("Erreur");
}
} |
Partager