Page 1 of 1

Using Template

PostPosted: Thu Feb 04, 2016 9:26 pm
by SMoltok

I'm trying to use template with docx4j but my output file seems to be corrupt and then the PDF file is created with many empty spaces...

I'm using Word from Mac is it the issue ?

Thanks for answering !

Re: Using Template

PostPosted: Thu Feb 04, 2016 9:40 pm
by SMoltok
I've tested to create my PDF directly from the original template docx without replacing the variables, and there is too many space....

Code :
Code: Select all
public static void convert(String inputfilepath) {
    try {
        //String inputfilepath = System.getProperty("user.dir") + "/simpleDoc.docx";

        WordprocessingMLPackage wordMLPackage;
        if (inputfilepath==null) {
            System.out.println("No imput path passed, creating dummy document");
             wordMLPackage = WordprocessingMLPackage.createPackage();
            // SampleDocument.createContent(wordMLPackage.getMainDocumentPart());
        } else {
            System.out.println("Loading file from " + inputfilepath);
            wordMLPackage = WordprocessingMLPackage.load(new;

        Mapper fontMapper = new IdentityPlusMapper();

        PhysicalFont font = PhysicalFonts.get("Comic Sans MS");

        //fontMapper.put("Algerian", font);

        FOSettings foSettings = Docx4J.createFOSettings();
        String outputfilepath;
        if (inputfilepath==null) {
            outputfilepath = System.getProperty("user.dir") + "/simpleDoc.pdf";
        } else {
            outputfilepath = inputfilepath + ".pdf";
        OutputStream os = new;
        Docx4J.toFO(foSettings, os, Docx4J.FLAG_NONE);
    } catch (Exception e) {

Re: Using Template

PostPosted: Thu Feb 04, 2016 10:09 pm
by SMoltok

There was a problem with a not Class Found Error.

The missing one :

I was using the following dependency :

but with the 1.1 version, it rules....

Is there something wrong ??

Re: Using Template

PostPosted: Sat Feb 06, 2016 8:01 am
by jason
Don't use xmlgraphics-commons 1.1; things will break.