Search in sources :

Example 1 with FieldsMetadata

use of fr.opensagres.xdocreport.template.formatter.FieldsMetadata in project Java-Tutorial by gpcodervn.

the class GenerateDocxReport method main.

public static void main(String[] args) throws IOException, XDocReportException {
    // 1) Load Docx file by filling Velocity template engine and cache it to the registry
    InputStream in = new FileInputStream("template/Project.docx");
    IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, TemplateEngineKind.Velocity);
    // 2) Create fields metadata to manage lazy loop (#forech velocity) for table row.
    // Create FieldsMetadata by setting Velocity as template engine
    FieldsMetadata fieldsMetadata = report.createFieldsMetadata();
    // Load fields metadata from Java Class
    fieldsMetadata.load("project", Project.class);
    // Load is called with true because model is a list of Developer.
    fieldsMetadata.load("developers", Developer.class, true);
    // 3) Create context Java model
    IContext context = report.createContext();
    Project project = new Project("XDocReport");
    context.put("project", project);
    // Register developers list
    context.put("developers", getDevelopers());
    // 4) Generate report by merging Java model with the Docx
    OutputStream out = new FileOutputStream(new File("Project_out.docx"));
    report.process(context, out);
}
Also used : Project(com.gpcoder.model.Project) IXDocReport(fr.opensagres.xdocreport.document.IXDocReport) FieldsMetadata(fr.opensagres.xdocreport.template.formatter.FieldsMetadata) IContext(fr.opensagres.xdocreport.template.IContext) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with FieldsMetadata

use of fr.opensagres.xdocreport.template.formatter.FieldsMetadata in project Java-Tutorial by gpcodervn.

the class GenerateXMLFields method main.

public static void main(String[] args) throws XDocReportException, IOException {
    // 1) Create FieldsMetadata by setting Velocity as template engine
    FieldsMetadata fieldsMetadata = new FieldsMetadata(TemplateEngineKind.Velocity.name());
    // 2) Load fields metadata from Java Class
    fieldsMetadata.load("project", Project.class);
    // Here load is called with true because model is a list of Developer.
    fieldsMetadata.load("developers", Developer.class, true);
    // 3) Generate XML fields in the file "project.fields.xml".
    // Extension *.fields.xml is very important to use it with MS Macro XDocReport.dotm
    // FieldsMetadata#saveXML is called with true to indent the XML.
    File xmlFieldsFile = new File("project.fields.xml");
    fieldsMetadata.saveXML(new FileOutputStream(xmlFieldsFile), true);
}
Also used : FieldsMetadata(fr.opensagres.xdocreport.template.formatter.FieldsMetadata) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 3 with FieldsMetadata

use of fr.opensagres.xdocreport.template.formatter.FieldsMetadata in project Java-Tutorial by gpcodervn.

the class GeneratePDF method main.

public static void main(String[] args) throws XDocConverterException, XDocReportException, IOException {
    // 1) Load Docx file by filling Velocity template engine and cache it to the registry
    InputStream in = new FileInputStream("template/Project.docx");
    IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, TemplateEngineKind.Velocity);
    // 2) Create fields metadata to manage lazy loop (#forech velocity) for table row.
    // Create FieldsMetadata by setting Velocity as template engine
    FieldsMetadata fieldsMetadata = report.createFieldsMetadata();
    // Load fields metadata from Java Class
    fieldsMetadata.load("project", Project.class);
    // Load is called with true because model is a list of Developer.
    fieldsMetadata.load("developers", Developer.class, true);
    // 3) Create context Java model
    IContext context = report.createContext();
    Project project = new Project("XDocReport");
    context.put("project", project);
    // Register developers list
    context.put("developers", getDevelopers());
    // 4) Generate report by merging Java model with the Docx
    OutputStream out = new FileOutputStream(new File("Project_Out.pdf"));
    // report.process(context, out);
    Options options = Options.getTo(ConverterTypeTo.PDF).via(ConverterTypeVia.XWPF);
    report.convert(context, options, out);
}
Also used : Project(com.gpcoder.model.Project) Options(fr.opensagres.xdocreport.converter.Options) IXDocReport(fr.opensagres.xdocreport.document.IXDocReport) FieldsMetadata(fr.opensagres.xdocreport.template.formatter.FieldsMetadata) IContext(fr.opensagres.xdocreport.template.IContext) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 4 with FieldsMetadata

use of fr.opensagres.xdocreport.template.formatter.FieldsMetadata in project Java-Tutorial by gpcodervn.

the class GenerateDocxReport method main.

public static void main(String[] args) throws IOException, XDocReportException {
    // 1) Load Docx file by filling Velocity template engine and cache it to the registry
    InputStream in = GenerateDocxReport.class.getResourceAsStream("project.docx");
    IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, TemplateEngineKind.Velocity);
    // 2) Create fields metadata to manage lazy loop (#forech velocity) for table row.
    // 1) Create FieldsMetadata by setting Velocity as template engine
    FieldsMetadata fieldsMetadata = report.createFieldsMetadata();
    // 2) Load fields metadata from Java Class
    fieldsMetadata.load("project", Project.class);
    // Here load is called with true because model is a list of Developer.
    fieldsMetadata.load("developers", Developer.class, true);
    // 3) Create context Java model
    IContext context = report.createContext();
    Project project = new Project("XDocReport");
    context.put("project", project);
    // Register developers list
    List<Developer> developers = new ArrayList<Developer>();
    developers.add(new Developer("Giang", "Phan", "gpcoder@gmail.com"));
    developers.add(new Developer("ZERR", "Angelo", "angelo.zerr@gmail.com"));
    context.put("developers", developers);
    // 4) Generate report by merging Java model with the Docx
    OutputStream out = new FileOutputStream(new File("project_out.docx"));
    report.process(context, out);
}
Also used : IXDocReport(fr.opensagres.xdocreport.document.IXDocReport) FieldsMetadata(fr.opensagres.xdocreport.template.formatter.FieldsMetadata) IContext(fr.opensagres.xdocreport.template.IContext) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) File(java.io.File)

Example 5 with FieldsMetadata

use of fr.opensagres.xdocreport.template.formatter.FieldsMetadata in project Java-Tutorial by gpcodervn.

the class GenerateXMLFields method main.

public static void main(String[] args) throws XDocReportException, IOException {
    // 1) Create FieldsMetadata by setting Velocity as template engine
    FieldsMetadata fieldsMetadata = new FieldsMetadata(TemplateEngineKind.Velocity.name());
    // 2) Load fields metadata from Java Class
    fieldsMetadata.load("project", Project.class);
    // Here load is called with true because model is a list of Developer.
    fieldsMetadata.load("developers", Developer.class, true);
    // 3) Generate XML fields in the file "project.fields.xml".
    // Extension *.fields.xml is very important to use it with MS Macro XDocReport.dotm
    // FieldsMetadata#saveXML is called with true to indent the XML.
    File xmlFieldsFile = new File("project.fields.xml");
    fieldsMetadata.saveXML(new FileOutputStream(xmlFieldsFile), true);
}
Also used : FieldsMetadata(fr.opensagres.xdocreport.template.formatter.FieldsMetadata) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

FieldsMetadata (fr.opensagres.xdocreport.template.formatter.FieldsMetadata)7 IXDocReport (fr.opensagres.xdocreport.document.IXDocReport)5 File (java.io.File)5 FileOutputStream (java.io.FileOutputStream)5 IContext (fr.opensagres.xdocreport.template.IContext)4 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)3 Project (com.gpcoder.model.Project)2 Options (fr.opensagres.xdocreport.converter.Options)2 FileInputStream (java.io.FileInputStream)2 XDocConverterException (fr.opensagres.xdocreport.converter.XDocConverterException)1 XDocReportException (fr.opensagres.xdocreport.core.XDocReportException)1 ByteArrayImageProvider (fr.opensagres.xdocreport.document.images.ByteArrayImageProvider)1 IImageProvider (fr.opensagres.xdocreport.document.images.IImageProvider)1 ByteArrayInOutStream (fr.univlorraine.ecandidat.utils.ByteArrayInOutStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1