2
votes

I am trying to convert a XSL-FO file with MathML to PDF using Apache FOP 2.1 but I get a few warnings and errors.

How can I get MathML to be printed to PDF using FOP?

My Test.fo file:

<?xml version="1.0" encoding="iso-8859-1"?>

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns="http://www.w3.org/1998/Math/MathML">
    <fo:layout-master-set>
        <fo:simple-page-master master-name="my-page">
            <fo:region-body margin="1in"/>
        </fo:simple-page-master>
    </fo:layout-master-set>
    <fo:page-sequence master-reference="my-page">
         <fo:flow flow-name="xsl-region-body" font="12pt Times">
            <fo:block font-size="1.5em" font-weight="bold" role="html:p">
                <fo:instream-foreign-object>
                    <math display="inline">
                        <mrow>
                            <mi>A</mi>
                            <mo>=</mo>
                            <mi>Ï€</mi>
                            <msup>
                                <mi>r</mi>
                                <mn>2</mn>
                            </msup>
                        </mrow>
                    </math>
                </fo:instream-foreign-object>
            </fo:block>
        </fo:flow>
    </fo:page-sequence>
</fo:root>

The output I get:

$ fop test.fo 123.pdf

Sep 30, 2016 1:45:12 PM org.apache.fop.events.LoggingEventListener processEvent WARNING: Unknown formatting object "{http://www.w3.org/1998/Math/MathML}math" encountered (a child of fo:instream-foreign-object}. (See position 13:72)

Sep 30, 2016 1:45:12 PM org.apache.fop.events.LoggingEventListener processEvent WARNING: Unknown formatting object "{http://www.w3.org/1998/Math/MathML}mrow" encountered (a child of math}. (See position 14:13)

Sep 30, 2016 1:45:12 PM org.apache.fop.events.LoggingEventListener processEvent WARNING: Unknown formatting object "{http://www.w3.org/1998/Math/MathML}mi" encountered (a child of mrow}. (See position 15:12)

Sep 30, 2016 1:45:12 PM org.apache.fop.events.LoggingEventListener processEvent WARNING: Unknown formatting object "{http://www.w3.org/1998/Math/MathML}mo" encountered (a child of mrow}. (See position 16:12)

Sep 30, 2016 1:45:12 PM org.apache.fop.events.LoggingEventListener processEvent WARNING: Unknown formatting object "{http://www.w3.org/1998/Math/MathML}mi" encountered (a child of mrow}. (See position 17:12)

Sep 30, 2016 1:45:12 PM org.apache.fop.events.LoggingEventListener processEvent WARNING: Unknown formatting object "{http://www.w3.org/1998/Math/MathML}msup" encountered (a child of mrow}. (See position 18:14)

Sep 30, 2016 1:45:12 PM org.apache.fop.events.LoggingEventListener processEvent WARNING: Unknown formatting object "{http://www.w3.org/1998/Math/MathML}mi" encountered (a child of msup}. (See position 19:13)

Sep 30, 2016 1:45:12 PM org.apache.fop.events.LoggingEventListener processEvent WARNING: Unknown formatting object "{http://www.w3.org/1998/Math/MathML}mn" encountered (a child of msup}. (See position 20:13)

Sep 30, 2016 1:45:12 PM org.apache.fop.events.LoggingEventListener processEvent SEVERE: The intrinsic dimensions of an instream-foreign-object could not be determined. (See position 12:33)

Sep 30, 2016 1:45:13 PM org.apache.fop.events.LoggingEventListener processEvent INFO: Rendered page #1.

The output PDF is empty.

2

2 Answers

1
votes

The open source project JEuclid includes a plugin for FOP.

Despite the plugin page stating that it works only with FOP 0.95beta or 0.95, I tested it with the latest FOP 2.1 and it works (0.95 was probably the latest version at the time of the last update of the web page).

This is the output I get, without any error or warning message:

screenshot of resulting PDF

You just need to:

  • download JEuclid
  • copy jeuclid-core-x.x.x.jar and jeuclid-fop-x.x.x.jar in FOP's lib/ directory (or create links)
  • run FOP as usual
0
votes

Building upon the answer by lfurini, the fop installation on Ubuntu 14.04 did not recognize the jeuclid's jar-files (version 3.1.9) in /usr/share/fop (or some subfolder /lib). I was able to get it to work by modifying /usr/bin/fop which is actually just a shell script wrapper. The modified parts are as follows:

...
find_jars /usr/share/fop/fop-hyph.jar
find_jars /usr/share/fop/jeuclid-core-3.1.9.jar
find_jars /usr/share/fop/jeuclid-fop-3.1.9.jar
find_jars fop
...

With this I was then able to compile above file without problems using

fop -fo test.fo -pdf test.pdf