如何使用 MathML 从 XSL-FO 转换为 PDF
How to convert to PDF from XSL-FO with MathML
我正在尝试使用 Apache FOP 2.1 将带有 MathML 的 XSL-FO 文件转换为 PDF,但我收到了一些警告和错误。
如何使用 FOP 将 MathML 打印成 PDF?
我的 Test.fo
文件:
<?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>
我得到的输出:
$ 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.
输出的 PDF 为空。
开源项目 JEuclid 包含一个 FOP 插件。
尽管 plugin page 声明它仅适用于 FOP 0.95beta 或 0.95,但我使用最新的 FOP 2.1 对其进行了测试并且它有效(0.95 可能是上次更新时的最新版本网页)。
这是我得到的输出,没有任何错误或警告消息:
您只需要:
- 下载JEuclid
- 在 FOP 的
lib/
目录中复制 jeuclid-core-x.x.x.jar
和 jeuclid-fop-x.x.x.jar
(或创建链接)
- 运行 照常付运价
根据 lfurini 的回答,Ubuntu 14.04 上的 fop 安装无法识别 /usr/share/fop[=18 中的 jeuclid 的 jar 文件(版本 3.1.9) =](或某个子文件夹/lib)。我能够通过修改 /usr/bin/fop 使其工作,这实际上只是一个 shell 脚本包装器。修改部分如下:
...
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
...
有了这个我就可以使用
毫无问题地编译上面的文件
fop -fo test.fo -pdf test.pdf
我正在尝试使用 Apache FOP 2.1 将带有 MathML 的 XSL-FO 文件转换为 PDF,但我收到了一些警告和错误。
如何使用 FOP 将 MathML 打印成 PDF?
我的 Test.fo
文件:
<?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>
我得到的输出:
$ 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.
输出的 PDF 为空。
开源项目 JEuclid 包含一个 FOP 插件。
尽管 plugin page 声明它仅适用于 FOP 0.95beta 或 0.95,但我使用最新的 FOP 2.1 对其进行了测试并且它有效(0.95 可能是上次更新时的最新版本网页)。
这是我得到的输出,没有任何错误或警告消息:
您只需要:
- 下载JEuclid
- 在 FOP 的
lib/
目录中复制jeuclid-core-x.x.x.jar
和jeuclid-fop-x.x.x.jar
(或创建链接) - 运行 照常付运价
根据 lfurini 的回答,Ubuntu 14.04 上的 fop 安装无法识别 /usr/share/fop[=18 中的 jeuclid 的 jar 文件(版本 3.1.9) =](或某个子文件夹/lib)。我能够通过修改 /usr/bin/fop 使其工作,这实际上只是一个 shell 脚本包装器。修改部分如下:
...
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
...
有了这个我就可以使用
毫无问题地编译上面的文件fop -fo test.fo -pdf test.pdf