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
| public void toPdf(){
conn = new connect_bdd().conn;
String sql= "SELECT * FROM outillage";
Document doc = new Document(PageSize.A4, 36, 36, 50, 100);
try{
Date dat =new Date();
DateFormat fd=DateFormat.getDateInstance(DateFormat.LONG);
FileSystemView fl=FileSystemView.getFileSystemView();
File fie=fl.getDefaultDirectory();
File dirpdf =new File(fie+"\\Facture\\InvOutil"+fd.format(dat));
dirpdf.mkdirs();
int list=dirpdf.listFiles().length;
fc=list;
File pdf = new File(dirpdf + "\\Outil("+fc+").pdf");
PdfWriter writer = PdfWriter.getInstance(doc , new FileOutputStream(pdf));
Image img = Image.getInstance("src\\Imagemaint\\entete w.png");
img.scaleAbsoluteHeight(100);
img.scaleAbsoluteWidth(580);
writer.setPageEvent(new MonPageEvent(img, 0, 0));
Image img1 = Image.getInstance("src\\Imagemaint\\pied w.png");
img1.scaleAbsoluteHeight(70);
img1.scaleAbsoluteWidth(575);
writer.setPageEvent(new MonPageEvent1(img1, 0, 0));
Image img2 = Image.getInstance("src\\Imagemaint\\pied direc.png");
img2.scaleAbsoluteHeight(20);
img2.scaleAbsoluteWidth(425);
writer.setPageEvent(new MonPageEvent2(img2, 50, 150));
doc.open();
Date gmt=new Date();
DateFormat gs=DateFormat.getDateInstance(DateFormat.SHORT);
String jours=gs.format(gmt).split("/")[0];
String moiss=gs.format(gmt).split("/")[1];
String ans=gs.format(gmt).split("/")[2];
String dits="20"+ans+"-"+moiss+"-"+jours;
String dits1 = jours + "/" +moiss+ "/" + "20"+ans;
doc.add(new Paragraph(" \n\n"));
doc.add(new Paragraph(" "));
doc.add(new Paragraph(" "));
Paragraph para0 = new Paragraph();
para0.add(new Chunk(" Garoua le : " + dits1 , new Font(Font.FontFamily.TIMES_ROMAN, 12)));
para0.setAlignment(Element.ALIGN_RIGHT);
doc.add(para0);
doc.setMargins(35f, 35f, 150f, 200f);
doc.add(new Paragraph(" \n\n"));
Paragraph para = new Paragraph();
para.add(new Chunk(" Récapitulatif Des Outils EWS /" +ans , new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD)).setUnderline(0.2f, -2f));
para.setAlignment(Element.ALIGN_CENTER);
doc.add(para);
doc.add(new Paragraph(" "));
PdfPTable table = new PdfPTable(3);
table.setWidthPercentage(100);
PdfPCell cell;
//// Debut Entete du tableau
cell = new PdfPCell(new Phrase("Code_Outil", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD)));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(BaseColor.CYAN);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Désignation", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD)));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(BaseColor.CYAN);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Quantité", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD)));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setBackgroundColor(BaseColor.CYAN);
table.addCell(cell);
///// Fin entete du Tableau
try
{
ResultSet str=conn.createStatement().executeQuery(sql);
while(str.next())
{
System.out.println("PDF CORRECT");
String cod = str.getString("code_outil");
String desi = str.getString("designation_outil");
String quan = str.getString("quantite");
cell = new PdfPCell(new Phrase(cod, new Font(Font.FontFamily.TIMES_ROMAN, 11)));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
cell = new PdfPCell(new Phrase(desi, new Font(Font.FontFamily.TIMES_ROMAN, 11)));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
cell = new PdfPCell(new Phrase(quan, new Font(Font.FontFamily.TIMES_ROMAN, 11)));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
}
}catch(Exception g){
g.printStackTrace();
}
doc.add(table);
float a = doc.getPageSize().getHeight() - doc.topMargin() - doc.bottomMargin();
System.out.println(a);
System.out.println(doc.topMargin());
System.out.println(doc.bottomMargin());
doc.close();
Desktop.getDesktop().open(new File(dirpdf+"\\Outil("+fc+").pdf"));
}
catch(Exception e)
{
e.printStackTrace();
}
} |
Partager