hyunsikki / xdocreport

Automatically exported from code.google.com/p/xdocreport
0 stars 0 forks source link

Text styling and dynamic image don't work in 1.0.0 and 1.0.5 #471

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi

  I have a test code for XDocReport that work fine with the version 0.9.8

If I try to use the version 1.0.0 or 1.0.5 with the same code and the same docx 
file, the text styling and dynamic image don't work.

This is my code and I attach the template docx file and the result docx file

// 1) Load Docx file by filling Freemarker template engine and cache
// it to the registry
final IXDocReport report = XDocReportRegistry.getRegistry().loadReport(new 
FileInputStream("E:/Temp/POI/Test.docx"),
        TemplateEngineKind.Freemarker);

final FieldsExtractor fields = new FieldsExtractor();
report.extractFields(fields);

for (int i = 0; i < fields.getFields().size(); i++) {
    final FieldExtractor field = (FieldExtractor) fields.getFields().get(i);

    System.out.println("Field : " + field.getName());
}

// 2) Create fields metadata to manage text styling
final FieldsMetadata metadata = report.createFieldsMetadata();
metadata.addFieldAsTextStyling("data", SyntaxKind.Html, true);
metadata.addFieldAsTextStyling("interfaces", SyntaxKind.Html);
metadata.addFieldAsImage("logo");

// report.setFieldsMetadata(metadata);

// 3) Create context Java model
final IContext context = report.createContext();

context.put("data", "<strong>Exigence 1 : </strong> blabla exigence 1"
        + "<br></br><br></br><strong>Exigence 2 : </strong> blabla exigence 2");

context.put("interfaces", "Here are severals styles :<ul>" + 
"<li><strong>Bold</strong> style.</li>" + "<li><em>Italic</em> style.</li>"
        + "<li><strong><em>BoldAndItalic</em></strong> style.</li>" + "</ul>" + "<p>Here are 3 styles :</p>" + "<ol>"
        + "<li><strong>Bold</strong> style.</li>" + "<li><em>Italic</em> style.</li>"
        + "<li><strong><em>BoldAndItalic</em></strong> style.</li>" + "</ol>"
        + "<p><a href=\"http://code.google.com/p/xdocreport/\">XDocReport</a> can manage those styles. "
        + "Now some <strong>headers</strong>:" + "</p>" + "<h1>Title 1</h1>" + "<p>Some text...</p>" + "<h2>Title 2</h2>"
        + "<p>Some text...</p>" + "<h3>Title 3</h3>" + "<p>Some text...</p>");

context.put("nom_prenom", "Seldon Hari");
context.put("today", "2014/02/12");
context.put("date_today_ddMMyyyy_HHmmss", "Cool");
context.put("logo", new FileImageProvider(new File("E:/Temp/POI/test_2.jpg"), 
false));

// 4) Generate report by merging Java model with the Docx
final OutputStream out = new FileOutputStream(new File("E:/Temp/POI/Test_" + 
System.currentTimeMillis() + ".docx"));
report.process(context, out);

Thank you for your help

Stephane

Original issue reported on code.google.com by pain.ste...@gmail.com on 8 Apr 2015 at 7:30

Attachments:

GoogleCodeExporter commented 9 years ago
That's very strange, are you sure you have none conflicts with old version of 
XDocReport?

Original comment by angelo.z...@gmail.com on 8 Apr 2015 at 8:45

GoogleCodeExporter commented 9 years ago
<dependency>
    <groupId>fr.opensagres.xdocreport</groupId>
    <artifactId>fr.opensagres.xdocreport.core</artifactId>
    <version>${xdocreport.version}</version>
</dependency>
<dependency>
    <groupId>fr.opensagres.xdocreport</groupId>
    <artifactId>fr.opensagres.xdocreport.document</artifactId>
    <version>${xdocreport.version}</version>
</dependency>
<dependency>
    <groupId>fr.opensagres.xdocreport</groupId>
    <artifactId>fr.opensagres.xdocreport.document.docx</artifactId>
    <version>${xdocreport.version}</version>
</dependency>
<dependency>
    <groupId>fr.opensagres.xdocreport</groupId>
    <artifactId>fr.opensagres.xdocreport.converter</artifactId>
    <version>${xdocreport.version}</version>
</dependency>

<dependency>
    <groupId>fr.opensagres.xdocreport</groupId>
    <artifactId>fr.opensagres.xdocreport.template.freemarker</artifactId>
    <version>${xdocreport.version}</version>
</dependency>

<dependency>
    <groupId>org.freemarker</groupId>
    <artifactId>freemarker</artifactId>
    <version>2.3.20</version>
</dependency>

Original comment by pain.ste...@gmail.com on 8 Apr 2015 at 3:58

GoogleCodeExporter commented 9 years ago
This is my dependencies in my pom.xml file

Original comment by pain.ste...@gmail.com on 8 Apr 2015 at 3:59

GoogleCodeExporter commented 9 years ago
Ok your problem is because your FieldsMetadata must be created on the first 
place before calling report.extractFields. 

In other words : 

--------------------------------------------------------------
// 1) Load Docx file by filling Freemarker template engine and cache
// it to the registry
final IXDocReport report = XDocReportRegistry.getRegistry().loadReport(new 
FileInputStream("E:/Temp/POI/Test.docx"),
        TemplateEngineKind.Freemarker);

// 2) Create fields metadata to manage text styling
final FieldsMetadata metadata = report.createFieldsMetadata();
metadata.addFieldAsTextStyling("data", SyntaxKind.Html, true);
metadata.addFieldAsTextStyling("interfaces", SyntaxKind.Html);
metadata.addFieldAsImage("logo");

final FieldsExtractor fields = new FieldsExtractor();
report.extractFields(fields);
for (int i = 0; i < fields.getFields().size(); i++) {
    final FieldExtractor field = (FieldExtractor) fields.getFields().get(i);

    System.out.println("Field : " + field.getName());
}
--------------------------------------------------------------

Original comment by angelo.z...@gmail.com on 9 Apr 2015 at 8:31

GoogleCodeExporter commented 9 years ago
It works. Thank you

Original comment by pain.ste...@gmail.com on 9 Apr 2015 at 9:14

GoogleCodeExporter commented 9 years ago
Ok that's cool. Next time please create issue at 
https://github.com/opensagres/xdocreport/issues

Original comment by angelo.z...@gmail.com on 9 Apr 2015 at 9:20