OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 182
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
Line 11... Line 11...
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.finance.accounting.report;
14
 package org.openconcerto.erp.core.finance.accounting.report;
15
 
15
 
16
import static org.openconcerto.task.config.ComptaBasePropsConfiguration.getStreamStatic;
16
import org.openconcerto.erp.generationDoc.TemplateManager;
17
 
-
 
18
import org.openconcerto.utils.ExceptionHandler;
17
import org.openconcerto.ui.preferences.TemplateProps;
19
 
18
 
20
import java.awt.Color;
19
import java.awt.Color;
21
import java.io.File;
20
import java.io.File;
-
 
21
import java.io.FileInputStream;
22
import java.io.FileNotFoundException;
22
import java.io.FileNotFoundException;
23
import java.io.FileOutputStream;
23
import java.io.FileOutputStream;
24
import java.io.IOException;
24
import java.io.IOException;
-
 
25
import java.io.InputStream;
25
import java.util.Calendar;
26
import java.util.Calendar;
26
import java.util.Date;
27
import java.util.Date;
27
import java.util.Map;
28
import java.util.Map;
28
 
29
 
-
 
30
import javax.swing.JOptionPane;
-
 
31
 
29
import com.ibm.icu.text.SimpleDateFormat;
32
import com.ibm.icu.text.SimpleDateFormat;
30
import com.lowagie.text.Document;
33
import com.lowagie.text.Document;
31
import com.lowagie.text.DocumentException;
34
import com.lowagie.text.DocumentException;
32
import com.lowagie.text.Rectangle;
35
import com.lowagie.text.Rectangle;
33
import com.lowagie.text.pdf.BaseFont;
36
import com.lowagie.text.pdf.BaseFont;
Line 56... Line 59...
56
    public static void main(String[] args) {
59
    public static void main(String[] args) {
57
        new PdfGenerator_2033B().generateFrom(null);
60
        new PdfGenerator_2033B().generateFrom(null);
58
    }
61
    }
59
 
62
 
60
    PdfGenerator(String fileNameIn, String fileNameOut, String directoryOut) {
63
    PdfGenerator(String fileNameIn, String fileNameOut, String directoryOut) {
61
        this.fileNameIn = "/Configuration/Template/PDF/" + fileNameIn;
64
        this.fileNameIn = fileNameIn;
62
        this.fileNameOut = fileNameOut;
65
        this.fileNameOut = fileNameOut;
63
        this.directoryOut = new File(directoryOut, String.valueOf(Calendar.getInstance().get(Calendar.YEAR)));
66
        this.directoryOut = new File(directoryOut, String.valueOf(Calendar.getInstance().get(Calendar.YEAR)));
64
    }
67
    }
65
 
68
 
66
    public void generateFrom(Map<String, String> m) {
69
    public void generateFrom(Map<String, String> m) {
Line 73... Line 76...
73
            this.cb.beginText();
76
            this.cb.beginText();
74
            generate();
77
            generate();
75
            this.cb.endText();
78
            this.cb.endText();
76
            this.document.close();
79
            this.document.close();
77
        } catch (FileNotFoundException e) {
80
        } catch (FileNotFoundException e) {
78
            ExceptionHandler.handle("Impossible de générer le fichier. \n" + e, e);
81
            JOptionPane.showMessageDialog(null, "Impossible de générer le fichier.\nModèle PDF non trouvé : " + e.getMessage());
79
        }
82
        }
80
    }
83
    }
81
 
84
 
82
    private void init() throws FileNotFoundException {
85
    private void init() throws FileNotFoundException {
83
 
86
 
84
        // we create a reader for a certain document
87
        // we create a reader for a certain document
85
        PdfReader reader = null;
88
        PdfReader reader = null;
86
        PdfWriter writer = null;
89
        PdfWriter writer = null;
87
        try {
90
        try {
-
 
91
            InputStream in = TemplateManager.getInstance().getTemplate(fileNameIn);
-
 
92
            if (in == null) {
-
 
93
                File defaultFile = new File("Configuration/Template/PDF/" + fileNameIn);
-
 
94
                System.err.println("PdfGenerator.init() template " + fileNameIn + " not retrieved from TemplateManager");
-
 
95
                if (defaultFile.exists()) {
-
 
96
                    in = new FileInputStream(defaultFile);
-
 
97
                } else {
-
 
98
                    System.err.println("PdfGenerator.init() template " + defaultFile.getAbsolutePath() + " not found in program directory");
-
 
99
                }
-
 
100
                final String property = TemplateProps.getInstance().getProperty("LocationTemplate");
-
 
101
                defaultFile = new File(property, fileNameIn);
-
 
102
 
-
 
103
                if (defaultFile.exists()) {
-
 
104
                    in = new FileInputStream(defaultFile);
-
 
105
                } else {
-
 
106
                    System.err.println("PdfGenerator.init() template " + defaultFile.getAbsolutePath() + " not found in template prefs directory");
-
 
107
                }
-
 
108
 
-
 
109
                if (in == null) {
-
 
110
                    throw new FileNotFoundException(fileNameIn);
-
 
111
                }
-
 
112
            }
-
 
113
 
88
            reader = new PdfReader(getStreamStatic(this.fileNameIn));
114
            reader = new PdfReader(in);
89
 
115
 
90
            final Rectangle psize = reader.getPageSize(1);
116
            final Rectangle psize = reader.getPageSize(1);
91
            psize.setRight(psize.getRight() - this.templateOffsetX);
117
            psize.setRight(psize.getRight() - this.templateOffsetX);
92
            psize.setTop(psize.getTop() - this.templateOffsetY);
118
            psize.setTop(psize.getTop() - this.templateOffsetY);
93
 
119