use of fr.opensagres.xdocreport.document.IXDocReport in project vitam-ui by ProgrammeVitam.
the class PdfFileGenerator method createPdfWithDynamicInfo.
/**
* Method allowing to fill an odt template with dynamic and static data and generate a pdf file from it.
*
* @param odtTemplateInputStream the odt template to fill and convert to pdf /!\ the owner is reponsible for closing the stream.
* @param pdfOutputStream the generated pdf file /!\ the owner is reponsible for closing the stream.
* @param dataMap the object containing the data to add to the template.
* @param dynamicFields the dynamic fields to add to the report to enable the creation of the pdf.
* @throws Exception
*/
public static void createPdfWithDynamicInfo(final InputStream odtTemplateInputStream, final OutputStream pdfOutputStream, final Map<String, Object> dataMap, final String... dynamicFields) throws Exception {
final IXDocReport xdocGenerator = generateXDocReport(odtTemplateInputStream, dynamicFields, new String[] {});
createPdfDocument(xdocGenerator, dataMap, pdfOutputStream);
}
use of fr.opensagres.xdocreport.document.IXDocReport 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 fr.opensagres.xdocreport.document.IXDocReport 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);
}
use of fr.opensagres.xdocreport.document.IXDocReport 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);
}
use of fr.opensagres.xdocreport.document.IXDocReport in project SORMAS-Project by hzi-braunschweig.
the class TemplateEngine method generateDocumentDocx.
public byte[] generateDocumentDocx(Properties properties, File templateFile) throws DocumentTemplateException {
try {
FileInputStream templateInputStream = new FileInputStream(templateFile);
IXDocReport report = readXDocReport(templateInputStream);
IContext context = report.createContext();
for (Object key : properties.keySet()) {
if (key instanceof String) {
Object property = properties.get(key);
// Sanitize property to avoid XML parsing errors
if (property instanceof Enum<?> && property.toString() != null) {
property = returnSanitizedString(property.toString());
} else if (property instanceof String) {
property = returnSanitizedString((String) property);
}
if (property != null && !(property instanceof String && ((String) property).isEmpty())) {
context.put((String) key, property);
}
}
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
report.process(context, outputStream);
return outputStream.toByteArray();
} catch (IOException | XDocReportException | VelocityException e) {
throw new DocumentTemplateException(String.format(I18nProperties.getString(Strings.errorDocumentGeneration), templateFile.getName()));
}
}
Aggregations