Page 1 of 1

pdf alignment problem after docx and XML merging

PostPosted: Fri Jan 08, 2016 3:04 am
by speedpak
Hi I am merging XML data into a docx template. But when I save the merged data into a pdf there are alignment issues.

I have a table which is right alligned in the docx template. when I merge it with XML the resulting docx file has proper alignment of all content containers but when saved as pdf the table is left aligned instead of being aligned to the right. And I also have border as box in Table properties but I get borders for all cells in the table in the resulting pdf file. I tried converting the docx file to pdf instead of saving the merged data as pdf; still I face the alignment issues and the border issues.

Re: pdf alignment problem after docx and XML merging

PostPosted: Fri Jan 08, 2016 7:50 pm
by jason
So the issue is with docx to PDF (ie has nothing to do with data binding).

I guess you are using the FO-based PDF output? Sounds like that needs to be enhanced for your case. Or you could try the commercial PDF Converter; see http://converter-eval.plutext.com/

Re: pdf alignment problem after docx and XML merging

PostPosted: Fri Jan 08, 2016 8:57 pm
by speedpak
I am using this below code to convert docx to pdf.

Code: Select all
PhysicalFonts.setRegex(null);
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(inputdocxfilepath);
FieldUpdater updater = new FieldUpdater(wordMLPackage);
updater.update(true);
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setWmlPackage(wordMLPackage);
Docx4J.toFO(foSettings, outputpdffilepath, Docx4J.FLAG_EXPORT_PREFER_XSL);


Can you please tell me jhow do I enhance this. I could not find documentation for this part.

Re: pdf alignment problem after docx and XML merging

PostPosted: Mon Jan 11, 2016 4:19 pm
by jason
Enhancement means forking the docx4j source code from GitHub...

There is a bit of documentation at https://github.com/plutext/docx4j/raw/m ... t_Out.docx
but fundamentally, you want to turn on saving the intermediate XSL FO. Work out what it needs to be, then change the code appropriately.

I'm afraid its a bit of a steep learning curve...

Re: pdf alignment problem after docx and XML merging

PostPosted: Thu Jan 14, 2016 2:52 am
by speedpak
Hi Jason.

Any suggestions on which class I should I start with to enhance the code?

Re: pdf alignment problem after docx and XML merging

PostPosted: Thu Jan 14, 2016 6:29 pm
by jason
Depends what you mean by "alignment", and whether its a style hierarchy issue or something else.

Post sample docx?

Re: pdf alignment problem after docx and XML merging

PostPosted: Fri Jan 15, 2016 12:57 am
by speedpak
I have added the docx file and the PDF file I get when I convert the same. You can see there that the first table is right aligned in the docx file but when converted to pdf it comes to the left and also with new online borders.