PDF generated from Docx lacks graphics and horizontal line

456 views
Skip to first unread message

alexand...@gmail.com

unread,
Aug 11, 2015, 8:08:24 AM8/11/15
to xdocreport
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
Template.docx

Angelo

unread,
Aug 11, 2015, 8:18:20 AM8/11/15
to xdocreport
Hi Alex,

Your problem is about our docx->pdf converter which is not perfect. It should be cool if you could attach your generated docx+pdf an dexplain more your problems in https://github.com/opensagres/xdocreport/issues

We wil try to fix your problem (if it's possible, because converter is very hard to developp) when we will find time.

Regard's Angelo
Reply all
Reply to author
Forward
0 new messages