Hey guys,
Fist of all thanks for your great work! I really like working with Xdocreport. But I ran into a problem, which I can't seem to fix.
I replace some placeholders in a template via Freemarker. The template was created with Office 2013. That works like a charm and the resulting Docx looks great. However when I create a PDF from it, some elements from the template are missing in the PDF:
- a watermark (please ignore the incorrect scaling in the template)
- a horizontal line
- a jpeg image (not in the attached template but I tried it)
Maybe it's a misconfiguration on my part. Here's my code:
ConvertibleOutputStream createPdfFrom(CreateDocRequest request) throws IOException, XDocReportException {
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(request.getTemplate(), TemplateEngineKind.Freemarker);
IContext context = report.createContext();
context.put("bill", request.getContents());
ConvertibleOutputStream docx = new ConvertibleOutputStream();
report.process(context, docx);
XWPFDocument document = new XWPFDocument(docx.toInputStream());
PdfOptions options = PdfOptions.create();
ConvertibleOutputStream pdf = new ConvertibleOutputStream();
PdfConverter.getInstance().convert(document, pdf, options);
/* This gives the same result:
ConvertibleOutputStream pdf = new ConvertibleOutputStream();
Options options = Options.getTo(ConverterTypeTo.PDF).via(ConverterTypeVia.XWPF);
report.convert(context, options, pdf);
*/
return pdf;
}ConvertibleOutputStream is a simple wrapper:
public class ConvertibleOutputStream extends ByteArrayOutputStream {
//Craetes InputStream without actually copying the buffer and using up mem for that.
public InputStream toInputStream(){
return new ByteArrayInputStream(buf);
}
public long getLength() {
return buf.length;
}
}Here's an excerpt from my pom.xml:
<properties>
<xdocreport.version>1.0.5</xdocreport.version>
</properties>
<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.template.freemarker</artifactId>
<version>${xdocreport.version}</version>
</dependency>
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>fr.opensagres.xdocreport.converter.docx.xwpf</artifactId>
<version>${xdocreport.version}</version>
</dependency>
This is a Dropwizard app with embedded Jetty running on Java 8. The problem occurs on Windows 7 and Amazon Linux (CentOS). Any help will be greatly appreciated.
Thank you very much!
Alex