Bonjour,
je développe une application ou je dois générer une facture PDF.
Je le crée avec itext5 et du coup je n'arrive pas à créer ce tableau complexe.
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 public class CreerPdfTableauComplexe { private static void ajoutSautLine(Paragraph paragraph, int number) { for (int i = 0; i < number; i++) { paragraph.add(new Paragraph(" ")); } } private void ajoutContenu(Document document, MonDTO monDTO) throws DocumentException, MalformedURLException, IOException { Resource logo = new ClassPathResource("static/img/logo.png"); Image image = Image.getInstance(logo.getFile().getPath()); image.scalePercent(15); PdfPTable table = new PdfPTable(2); table.setWidths(new int[] { 5, 5 }); table.setWidthPercentage(100); Paragraph numeroObjet = new Paragraph("numero " + monDTO.getNumero().toString(), Font); PdfPCell cell1 = new PdfPCell(); cell1.addElement(image); cell1.setRowspan(3); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell1.setBorder(0); table.addCell(cell1); PdfPCell cell2 = new PdfPCell(); cell2 = new PdfPCell(); cell2.addElement(numeroObjet ); cell2.setBorder(0); table.addCell(cell2); document.add(table); Paragraph espace = new Paragraph(); ajoutSautLine(espace, 3); document.add(espace); //Ajout tableau complexe // c'est ici que je vais faire mon tableau complexe en pièce jointe } public void creerPdf(MonDTO monDTO, String filePath) throws MalformedURLException, IOException { try { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(new File(filePath))); document.open(); ajoutContenu(document, monDTO); document.close(); } catch (DocumentException e) { e.getMessage(); } } }
Partager