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
|
public class EditionPDF {
private static EditionPDF m_Instance = null;
private IReportEngine engine;
private String realPath;
private IRenderOption option;
private String etat;
private String chemin;
private HashMap parametres;
private String format;
private Locale langue;
private OutputStream flux;
private EditionPDF() throws BirtException {
EngineConfig config = new EngineConfig();
realPath ="F:\\dev\\eclipse workspace\\hello\\WebContent\\";
config.setEngineHome("F:\\dev\\eclipse workspace\\hello\\WebContent\\WEB-INF\\ReportEngine");
Platform.startup(config);
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
engine = factory.createReportEngine(config);
option = new RenderOption();
HTMLCompleteImageHandler imageHandler = new HTMLCompleteImageHandler();
option.setImageHandler(imageHandler);
option.setSupportedImageFormats("JPG;BMP;SVG;PNG");
option.setOutputStream(flux);
}
public static EditionPDF getInstance() throws BirtException {
if (m_Instance == null)
m_Instance = new EditionPDF();
return m_Instance;
}
public void init(String etat, String chemin,
HashMap parametres, String format, OutputStream flux) {
this.etat = etat;
this.chemin = chemin;
this.parametres = parametres;
this.format = format;
this.flux = flux;
}
public void run() {
try {
IReportRunnable design = engine.openReportDesign(new File(realPath,
"WEB-INF/reports/" + etat + ".rptdesign").getAbsolutePath());
IRunAndRenderTask task = engine.createRunAndRenderTask(design); // Crée
task.setParameterValue("realPath", realPath);
/* Création PDF */
// option.setOutputFileName(chemin); // Nom du fichier de sortie
option.setOutputStream(flux);
option.setOutputFormat(format); // Format du fichier de sortie
// task.setLocale(langue);
task.setRenderOption(option); // Chargement du fichier
/* Fin création PDF */
task.run(); // Création du fichier
} catch (EngineException e) {
e.printStackTrace();
}
}
public void destructeur() {
engine.destroy();
} |
Partager