0

I am attempting to convert a XWPFDocument to PDF format and everything except the maths formulas are being exported. I believe this is to do with the convert method in opensagres's PdfConverter class.

When decompiling and attempting to search for the root of the problem, it led me to the visitBodyElements method in the XWPFDocumentVisitor class.

protected void visitBodyElements(List<IBodyElement> bodyElements, T container) throws Exception {
    if (!this.masterPageManager.isInitialized()) {
        this.masterPageManager.initialize();
    }

    String previousParagraphStyleName = null;

    for(int i = 0; i < bodyElements.size(); ++i) {
        IBodyElement bodyElement = (IBodyElement)bodyElements.get(i);

        switch(bodyElement.getElementType()) {
            case PARAGRAPH:
                XWPFParagraph paragraph = (XWPFParagraph)bodyElement;
                String paragraphStyleName = paragraph.getStyleID();
                boolean var10000;
                if (paragraphStyleName != null && paragraphStyleName.equals(previousParagraphStyleName)) {
                    var10000 = true;
                } else {
                    var10000 = false;
                }

                this.visitParagraph(paragraph, i, container);
                break;

            case TABLE:
                previousParagraphStyleName = null;
                this.visitTable((XWPFTable)bodyElement, i, container);
                break;

            case CONTENTCONTROL:
                this.visitSDT((XWPFSDT)bodyElement, i, container);
        }
    }

}

This method does not contain a case where the bodyElement is a formula and I believe this is why it is not being converted to PDF. However, it that the case? How are Maths formulas being stored in the XWPFDocument class?

  • 1
    At first `XWPFDocumentVisitor` is not a `apache poi`class but a [XDocReport](https://github.com/opensagres/xdocreport/blob/master/thirdparties-extension/fr.opensagres.poi.xwpf.converter.core/src/main/java/fr/opensagres/poi/xwpf/converter/core/XWPFDocumentVisitor.java) class. `XDocReport` uses `apache poi` but both projects are not related to each other. And no, it does not considering [Office MathML](https://en.wikipedia.org/wiki/Office_Open_XML_file_formats#Office_MathML_.28OMML.29) equations up to now. So pull an issue or a request [there](https://github.com/opensagres/xdocreport). – Axel Richter Jan 17 '22 at 14:00
  • 1
    I have provided code to convert that not really well known `Office MathML` to the better known [MathML](https://en.wikipedia.org/wiki/MathML): https://stackoverflow.com/questions/44748712/reading-equations-formula-from-word-docx-to-html-and-save-database-using-jav/44809755#44809755 and https://stackoverflow.com/questions/59414033/reading-equations-from-word-docx-to-html-together-with-their-text-context-us/59502090#59502090. But converting that into PDF will be a much more tedious task then. – Axel Richter Jan 17 '22 at 14:05
  • Is "`` enter code here`` " [intentional](https://stackoverflow.com/posts/70742097/edit)? (Last line in the posted code.) – Peter Mortensen Jan 17 '22 at 14:21
  • Thanks for the feedback! Does anyone have an idea on how we could go about getting these maths formulas into pdf as well as powerpoint. – Donald Jennings Jan 19 '22 at 10:45

0 Answers0