Document problem

Hi.
I did the following groovysript for create a document:

import fr.opensagres.xdocreport.core.XDocReportException;
import fr.opensagres.xdocreport.document.IXDocReport;
import fr.opensagres.xdocreport.document.registry.XDocReportRegistry;
import fr.opensagres.xdocreport.template.IContext;
import fr.opensagres.xdocreport.template.TemplateEngineKind;
import java.io.*;
import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeManager;
OfficeManager officeManager = null;
try{
// 1) Load ODT file and set Velocity template engine and cache it to the registry
InputStream inp= new FileInputStream(new File(“D:/document.odt”));
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(inp,TemplateEngineKind.Velocity);

// 2) Create Java model context
IContext context = report.createContext();
context.put(“namePerson”, “${namePerson}”);
context.put(“lastnamePerson”, “${lastnamePerson}”);

// 3) Generate report by merging Java model with the ODT
OutputStream out = new FileOutputStream(new File(“D:/newDocument.odt”));
report.process(context, out);

officeManager = new DefaultOfficeManagerConfiguration().setOfficeHome(new File("C:/Program Files (x86)/OpenOffice 4")).buildOfficeManager();
officeManager.start();

OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);
createPDF(converter);
createPDF(converter);

}
finally
{
if(officeManager != null){
officeManager.stop();
}
}

public static void createPDF(OfficeDocumentConverter converter){
try{
converter.convert(new File(“D:/newDocument.odt”), new File(“D:/newDocument_Pdf.pdf”));
}catch(Throwable e){
e.printStackTrace();
}
}

I added the jars in “Manage jars”
I don’t know what is the problem, I test this in other IDE, the script works.

1 Like

I only change the names of the variables in this step:
Before
// 2) Create Java model context
IContext context = report.createContext();
context.put(“namePerson”, “${namePerson}”);
context.put(“lastnamePerson”, “${lastnamePerson}”);

After
// 2) Create Java model context
IContext context = report.createContext();
context.put(“name”, “${namePerson}”);
context.put(“lastname”, “${lastnamePerson}”);

The script works correctly.

1 Like

A small hint here. Don’t use the “code” buttons from Bonita (as above) they don’t work as you can see,

Start code blocks with < code > and end with < /code > removing the spaces and it will format the code correctly

regards
Seán

What version/edition of Bonitasoft are you using? Always helps.

Have you added the jars to the /lib folder?

yes, I did add the jars
the version is 7.2

How do you know it’s not working? Where are the error reports/logs?

regards

The problem was with this library:
import fr.opensagres.xdocreport.document.IXDocReport;

1 Like