Bonjour à tous,

Je suis en train de découvrir iText pour faire des pdf.
ça fonctionne plutôt bien mais je n'arrive pas à faire des header et des footer.

Voici mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
try{
			PdfWriter.getInstance(document, baos);
			document.addTitle("ddedejdejdizjiozjodijo");
			document.addHeader("cczczrfzrfz", "frfrzefezrfrefer");
			document.addCreationDate();
			System.out.println();
			document.open();
			Image img = Image.getInstance("Workspace/win/WebContent/images/zoomold.jpg");
			img.scalePercent(100);
			Phrase h1 = new Phrase("header 1");
			Phrase h2 = new Phrase("header 2");
			HeaderFooter header = new HeaderFooter(h1,h2);
			document.setHeader(header);
			Phrase f1 = new Phrase("footer 1");
			Phrase f2 = new Phrase("footer 2");
			HeaderFooter footer = new HeaderFooter(f1,f2);
			document.setFooter(footer);
			document.add(header);
			document.add(footer);
			Font fontRed = FontFactory.getFont(FontFactory.COURIER, 8, Font.NORMAL, new Color(255,0,0));
			Font fontTitre =  new Font(Font.HELVETICA,Font.DEFAULTSIZE,Font.BOLD);
			Font fontLibelle =  new Font(Font.HELVETICA,8,Font.NORMAL);
			Phrase libNumTrans = new Phrase("Numéro de transaction :",fontLibelle);
			Phrase intNumTrans = new Phrase(String.valueOf(numTransaction),fontLibelle);
			Phrase titre = new Phrase("Photo du bien",fontRed);
			PdfPTable table = new PdfPTable(2);
			PdfPCell cell = new PdfPCell(new Paragraph(titreEdTransaction,fontTitre));
			Cell celltest = new Cell(cell);
			cell.setColspan(2);
			cell.setHorizontalAlignment(Cell.ALIGN_CENTER);
			cell.setVerticalAlignment(Cell.ALIGN_CENTER);
			celltest.setHeader(true);
			table.addCell(cell);
			table.addCell(libNumTrans);
			table.addCell(intNumTrans);
			table.addCell("Adresse : ");
			table.addCell(numVoie.trim()+", "+typeVoie.trim()+" "+nomVoie.trim()+", "+codePostal.trim()+" "+commune.trim());
			table.addCell("Négociateur : ");
			table.addCell(prenomNego.trim()+" "+nomNego.trim());
			table.addCell(titre);
			table.addCell(img);
			document.add(table);
			PdfPTable tableCustomized = new PdfPTable(3);
			PdfPTable tableNested = new PdfPTable(6);
			Phrase type = new Phrase("Type :",fontLibelle);
			Phrase surface = new Phrase("Surface :",fontLibelle);
			Phrase venteloc = new Phrase("Vente / Location :",fontLibelle);
			tableNested.addCell(type);
			tableNested.addCell(surface);
			tableNested.addCell(venteloc);
			tableNested.addCell("Bureau");
			tableNested.addCell("5000 m²");
			tableNested.addCell("Vente");
			tableCustomized.setTotalWidth(40);
			PdfPCell cellule = new PdfPCell(new Paragraph("test table",fontTitre));
			cellule.setBackgroundColor(new Color(0,255,255));
			cellule.setBorder(0);
			tableCustomized.addCell(cellule);
			tableCustomized.addCell("fffff");
			tableCustomized.addCell("ddedede");
			tableCustomized.addCell("cecrftg");
			tableCustomized.addCell("ffhyjjuj");
			tableCustomized.addCell(tableNested);
			document.add(tableCustomized);
			document.close();
			response.setContentType("application/pdf");
			response.setContentLength(baos.size());
			ServletOutputStream out = response.getOutputStream();
			baos.writeTo(out);
			out.flush();
		} catch(DocumentException de){
			System.out.println("Pb PDF : "+de);
		}
si quelqu'un peut m'aider.......

Merci