| 12
 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
 
 |  
public static void exportFacturePDF(Commande commande) {
		int id_Commande = Integer.valueOf(Init.getDevis());
		File fichiermaster = new File("src/other/file/MasterFacture.pdf");
		String masterPath = fichiermaster.getAbsolutePath();
		String path = Init.getDossier() + "Facture_n°_" + Init.getDevis() + "_" + commande.getClient().getSociete() + ".pdf";
		try(PdfReader reader = new PdfReader(masterPath);
			PdfWriter writer = new PdfWriter(new File(path));
			PdfDocument document = new PdfDocument(reader, writer)){
 
			PdfPage page = document.getFirstPage();
			PdfCanvas canvas = new PdfCanvas(page);
			FontProgram fontprogram = FontProgramFactory.createFont();
			PdfFont font = PdfFontFactory.createFont(fontprogram, PdfEncodings.UTF8, true);
			canvas.setFontAndSize(font, 12);
			canvas.beginText();
 
			canvas.setTextMatrix(130,660);
			canvas.showText(" " + id_Commande);
 
			canvas.setTextMatrix(130,639);
			canvas.showText(" " + LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")));
 
			canvas.setTextMatrix(340,719);
			canvas.showText(commande.getClient().getSociete());
 
			canvas.setTextMatrix(340,703);
			canvas.showText(commande.getClient().getAdresse());
 
			canvas.setTextMatrix(340,687);
			canvas.showText(commande.getClient().getCP() + " " + commande.getClient().getVille());
 
			int x = 575;
 
			for (CommandeProduit produit : commande.getProduit()) {
				canvas.setTextMatrix(80, x);
				canvas.showText("" + produit.getQte());
 
				canvas.setTextMatrix(160, x);
				canvas.showText(produit.getProduit().getNom());
 
				canvas.setTextMatrix(305, x);
				canvas.showText(produit.getProduit().getPoids() + "g");
 
				canvas.setTextMatrix(410, x);
				canvas.showText(produit.getProduit().getPu() + "");
 
				canvas.setTextMatrix(500, x);
				canvas.showText(produit.getProduit().getPu() * produit.getQte() +"");
 
				x -= 20;
			}
 
 
			canvas.setTextMatrix(500, 210);
			canvas.showText("4.50");
 
			canvas.setTextMatrix(500, 180);
			canvas.showText("4.50");
 
			canvas.setTextMatrix(500, 152);
			canvas.showText("4.50");
 
			canvas.endText();
 
			Init.setNBFacture();
 
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	} | 
Partager