Kenmegne
6 days ago 6494941037ae2670876de9940853d50538eb5129
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
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
 */
package com.megatim.reporting.adhoc;
 
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.util.JRLoader;
 
/**
 *
 * @author ASUS
 */
public class App {
 
    public final static File templateListe = new File("C:\\Users\\ASUS\\Documents\\templateEtats.xml");
    public final static File templateDetail = new File("C:\\Users\\ASUS\\Documents\\templateEtatsDetail.xml");
 
    public static void main(String[] args) {
        String str = "\t\tmoi     hghruhrih         \niroriotor\naem\t\tp\t\t";
 
        String result = str.trim()
                .replaceAll("(?U)\\s+", " ");
//                .replaceAll("(?U)\\G\\s", "");
        System.out.println("----------------- before ----------------------------");
        System.out.println(str);
        System.out.println("--------------------after-------------------------");
        System.out.println("begin" + result + "end");
 
//        String jrxmlPath = "C:\\Users\\ASUS\\Documents\\etats\\etats_horizon";
//        String pdfPath = "C:\\Users\\ASUS\\Documents\\etats\\etats_horizon\\pdfs";
//        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
//
//        try {
//            String jasperFile = new Processor().process(new CategorieDetailConstruct().construct(jrxmlPath));
////            String jasperFile = new Processor().process(templateDetail, new ComiteDetailConstruct().construct(jrxmlPath));
//
//            List<ComiteRapport> liste = ComiteDataSource.createBeanCollection();
//
//            HashMap<String, Object> map = new HashMap<>();
//            map.put("MONTANT_TOTAL", new BigDecimal("642555.36915"));
//            map.put("TITRE", "LISTE DES ENTREPRISES");
//            map.put("LOGIN_UTILISATEUR", "Mela");
//            map.put("VERSION", "HORIZON");
//            map.put("LOGO_CENTRE", jrxmlPath + "\\images\\logo.jpg");
//            map.put("NOMBRE_TOTAL", liste.size() + "");
//            map.put("SUBREPORT_DIR", jrxmlPath + File.separator);
//
//            genererFichierPdf(liste, Paths.get(pdfPath, "ComiteDetail" + dtf.format(LocalDateTime.now()) + ".pdf").toString(),
//                    jasperFile, map);
//        } catch (Exception ex) {
//            Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
//        }
    }
 
    public static File genererFichierPdf(List<?> datas, String pdfFile, String reportFilePath, Map params) throws Exception {
 
        // Creation d'un File sur le fichier
        File reportFile = new File(reportFilePath);
        File fichierGenerer = new File(pdfFile);
 
        //On cree le fichier s'ile n'existe pas
        if (!fichierGenerer.exists()) {
 
            //On cree le fichier
            fichierGenerer.createNewFile();
 
        }
 
        // Chargement du Rapport
        JasperReport report = null;
 
        // Etat rempli
        JasperPrint jasperPrint = null;
 
        // Chargement du report
        report = (JasperReport) JRLoader.loadObject(reportFile);
        jasperPrint = JasperFillManager.fillReport(report, params, new JRBeanCollectionDataSource(datas, false));
 
        OutputStream output = new FileOutputStream(fichierGenerer);
        JasperExportManager.exportReportToPdfStream(jasperPrint, output);
        output.close();
 
        return fichierGenerer;
    }
 
}