Document problem

1
0
-1

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.

Comments

Submitted by Sean McP on Fri, 07/15/2016 - 06:14

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

Submitted by Sean McP on Fri, 07/15/2016 - 06:22

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

Have you added the jars to the /lib folder?

Submitted by PImgmp on Fri, 07/15/2016 - 06:25

yes, I did add the jars
the version is 7.2

Submitted by Sean McP on Fri, 07/15/2016 - 06:24

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

regards

Submitted by PImgmp on Fri, 07/15/2016 - 06:29

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

1 answer

1
0
-1
This one is the BEST answer!

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.

Notifications