Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doc4j - Having issues converting docx to PDF with tables in the document

I just tried to a docx document through docx4j's sample webapp at: http://webapp.docx4java.org/OnlineDemo/docx_to_pdf_fop.html the resulting PDF file had the tables incorrectly formatted. In fact the tables were significantly off...

I'm just wondering if it's because docx4j doesn't properly support tables or it's an error of some sort. And if so, if anyone could point me to the proper information.

like image 770
Stephane Grenier Avatar asked Sep 19 '25 01:09

Stephane Grenier


1 Answers

https://github.com/plutext/docx4j/blob/master/docx4j-samples-docx4j/sample-docs/tables.docx is an example of various table features we can process.

Without seeing your docx (and absent any description in your question of the disparity!), I'd say either:

  1. you're using some table feature we don't support yet, or

  2. if the document is 30 pages long, or its document.xml longer than 300KB, the faster 'non XSLT' code will be used. This code doesn't have feature parity yet.

2020 Sept Update

For some context, there are 3 main ways to do docx to PDF in the docx4j world:

  • older/cheerful approach: using docx4j-export-fo (which is the XSL FO approach discussed here, and which that tables sample document is for)
  • using Microsoft Word running locally or remotely, driven by documents4j. In docx4j 8.2.0, see https://github.com/plutext/docx4j/tree/master/docx4j-samples-documents4j-local/src/main/java/org/docx4j/samples/documents4j/local or the -remote sub-project.
  • using Microsoft Graph. In docx4j 8.2.3, see samples at https://github.com/plutext/docx4j/tree/master/docx4j-samples-conversion-via-microsoft-graph/src/main/java/org/docx4j/samples/graph_convert This uses https://github.com/plutext/java-docx-to-pdf-using-Microsoft-Graph

docx4j will automatically use export-fo if the jar is on your classpath.

For a comparison between these approaches, see https://www.docx4java.org/blog/2020/09/office-pptxxlsxdocx-to-pdf-to-in-docx4j-8-2-3/

like image 112
JasonPlutext Avatar answered Sep 20 '25 14:09

JasonPlutext