use of com.gpcoder.model.Project 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);
}
use of com.gpcoder.model.Project 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);
}
Aggregations