无法使用 Apache FOP 生成 PDF

2024-03-19

我正在尝试使用 Apache FOP 使用 XML 数据和 XSL 样式表创建 PDF,但我不断收到以下错误

org.apache.fop.apps.FOPException: org.apache.fop.fo.ValidationException: “{http://www.w3.org/1999/XSL/Format http://www.w3.org/1999/XSL/Format}block" 不是以下的有效子项 “fo:根”! (没有可用的上下文信息) javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: “{http://www.w3.org/1999/XSL/Format http://www.w3.org/1999/XSL/Format}block" 不是以下的有效子项 “fo:根”! (没有可用的上下文信息)

奇怪的是,当我在本地 Windows 计算机上测试它时,它工作正常,但当我尝试在 Debian 服务器上执行相同操作时,我收到此错误。

我正在命令行上执行以下操作

fop -c fop_config.xml -xml /tmp/fop4IwJKZ -xsl stylesheet.xsl -pdf pdf.pdf

下面是我的 XML:

<?xml version="1.0" encoding="UTF-8"?>
<report>
    <heading>Heading</heading>
    <mailersent>18/06/2013 14:23</mailersent>
    <reportgenerated>18/06/2013 17:26</reportgenerated>
    <portrait>
        <title>Summary</title>
        <graph>graphs/graph1.png</graph>
        <stats>
            <stat>
                <value>16.67%</value>
                <text>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor</text>
            </stat>
            <stat>
                <value>2.25%</value>
                <text>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor</text>
            </stat>
            <stat>
                <value>13.49%</value>
                <text>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor through</text>
            </stat>
            <stat>
                <value>8.99%</value>
                <text>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor</text>
            </stat>
        </stats>
        </portrait>
</report>

样式表:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="node()|@*">
    <xsl:apply-templates select="node()|@*"/>
</xsl:template>

<xsl:template match="/report">
    <fo:root>
        <fo:layout-master-set>
            <fo:simple-page-master master-name="portraitLayout" page-height="29.7cm" page-width="21.0cm" margin="1cm">
                <fo:region-body margin-bottom="1cm"/>
                <fo:region-after extent="1cm"/>
            </fo:simple-page-master>
            <fo:simple-page-master master-name="landscapeLayout" page-height="21cm" page-width="30cm" margin="1cm">
                <fo:region-body margin-bottom="1cm"/>
                <fo:region-after extent="1cm"/>
            </fo:simple-page-master>
        </fo:layout-master-set>

        <fo:page-sequence master-reference="portraitLayout">
            <fo:flow flow-name="xsl-region-body">
                <xsl:call-template name="heading"/>
            </fo:flow>
        </fo:page-sequence>

        <fo:page-sequence master-reference="portraitLayout">
            <fo:flow flow-name="xsl-region-body">
                <xsl:call-template name="genTOC"/>
            </fo:flow>
        </fo:page-sequence>
        <xsl:apply-templates/>
    </fo:root>
</xsl:template>

<xsl:template name="genTOC">
    <fo:block break-before='page'>
        <fo:block margin-bottom="1cm" font-size="16pt" font-weight="bold" text-align="center">Contents</fo:block>
        <xsl:for-each select="//portrait|//landscape">
            <fo:block text-align-last="justify">
                <fo:basic-link internal-destination="{generate-id(.)}">
                    <xsl:value-of select="title" />
                    <fo:leader leader-pattern="dots" />
                    <fo:page-number-citation ref-id="{generate-id(.)}" />
                </fo:basic-link>
            </fo:block>
        </xsl:for-each>
    </fo:block>
</xsl:template>

<xsl:template match="portrait">
    <fo:page-sequence master-reference="portraitLayout" id="{generate-id(.)}">
        <fo:static-content flow-name="xsl-region-after">
            <fo:block font-size="8pt" text-align="center" border-top-color="#000000" border-top-style="solid" border-top-width=".3mm" padding-top="0.2cm">
                Page <fo:page-number/> of 9
            </fo:block>
        </fo:static-content>
        <fo:flow flow-name="xsl-region-body">
            <xsl:apply-templates/>
        </fo:flow>
    </fo:page-sequence>
</xsl:template>

<xsl:template match="landscape">
    <fo:page-sequence master-reference="landscapeLayout" id="{generate-id(.)}">
        <fo:static-content flow-name="xsl-region-after">
            <fo:block font-size="8pt" text-align="center" border-top-color="#000000" border-top-style="solid" border-top-width=".3mm" padding-top="0.2cm">
                Page <fo:page-number/> of 9
            </fo:block>
        </fo:static-content>
        <fo:flow flow-name="xsl-region-body">
            <xsl:apply-templates/>
        </fo:flow>
    </fo:page-sequence>
</xsl:template>

<xsl:template name="heading">
    <fo:block margin-top="10cm" font-size="21pt" font-weight="bold" text-align="center">
        <xsl:value-of select="heading"/>
    </fo:block>
    <fo:block margin-top="0.3cm" font-size="16pt" text-align="center">
        <xsl:text>Mailer sent: </xsl:text>
        <xsl:value-of select="mailersent"/>
    </fo:block>
    <fo:block margin-top="0.3cm" font-size="16pt" text-align="center">
        <xsl:text>Report generated: </xsl:text>
        <xsl:value-of select="reportgenerated"/>
    </fo:block>
</xsl:template>

<xsl:template match="title">
    <fo:block margin-bottom="0.5cm" border-bottom-color="#000000" border-bottom-style="solid" border-bottom-width=".5mm" font-size="20pt">
        <xsl:value-of select="."/>
    </fo:block>
</xsl:template>

<xsl:template match="graph">
    <fo:block margin-bottom="0.5cm" border-color="#d8d8d8" border-style="solid" border-width=".3mm" font-size="10pt">
        <xsl:variable name="graphimage">
            <xsl:value-of select="."/>
        </xsl:variable>
        <fo:external-graphic src="{$graphimage}" content-height="scale-to-fit" content-width="16cm" scaling="non-uniform"/>
    </fo:block>
</xsl:template>

<xsl:template match="svggraph">
    <fo:block margin-bottom="0.5cm" border-color="#d8d8d8" border-style="solid" border-width=".3mm" font-size="10pt">
        <fo:instream-foreign-object xmlns:svg="http://www.w3.org/2000/svg" content-width="19cm" content-height="5cm">
        <svg:svg width="25" height="25">
        <svg:g style="fill:red; stroke:#000000">
        <svg:rect x="0" y="0" width="15" height="15"/>
        <svg:rect x="5" y="5" width="15" height="15"/>
        </svg:g>
        </svg:svg>
        </fo:instream-foreign-object>
    </fo:block>
</xsl:template>

<xsl:template match="stats">
    <xsl:for-each select="stat">
        <fo:block margin-bottom="0.5cm" font-size="10pt">
            <fo:inline font-weight="bold" font-size="12pt">
                <xsl:value-of select="value"/>
            </fo:inline>
            <xsl:text> </xsl:text>
            <xsl:value-of select="text"/>
        </fo:block>
    </xsl:for-each>
</xsl:template>

<xsl:template match="table">
    <fo:block>
        <fo:table margin-bottom="0.5cm" border-collapse="separate" border-color="#d8d8d8" border-style="solid" border-width=".3mm" table-layout="fixed" width="100%" font-size="10pt">

            <xsl:for-each select="thead/tr/th">
                <xsl:choose>
                    <xsl:when test="width">
                        <xsl:variable name="columnwidth">
                            <xsl:value-of select="width" />
                        </xsl:variable>
                        <fo:table-column column-width="{$columnwidth}"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <fo:table-column/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:for-each>

            <fo:table-header background-color="#ededed">                    
                <xsl:for-each select="thead/tr/th">
                    <fo:table-cell padding-top="5pt" padding-bottom="5pt" padding-left="3pt" padding-right="3pt">
                        <fo:block font-weight="bold">
                            <xsl:value-of select="heading"/>
                        </fo:block>
                    </fo:table-cell>
                </xsl:for-each>                 
            </fo:table-header>
            <fo:table-body>                 
                <xsl:for-each select="tbody/tr">                        
                    <xsl:variable name="row-background">
                        <xsl:choose>
                            <xsl:when test="position() mod 2 = 0">#f8f8f8</xsl:when>
                            <xsl:otherwise>#ffffff</xsl:otherwise>
                        </xsl:choose>
                    </xsl:variable>                     
                    <fo:table-row background-color="{$row-background}">                         
                        <xsl:for-each select="td">
                            <fo:table-cell padding-top="5pt" padding-bottom="5pt" padding-left="3pt" padding-right="3pt">
                                <fo:block>
                                    <xsl:value-of select="."/>
                                </fo:block>
                            </fo:table-cell>
                        </xsl:for-each>                         
                    </fo:table-row>                     
                </xsl:for-each>
            </fo:table-body>
        </fo:table>
    </fo:block>
</xsl:template>

<xsl:template match="text">
    <fo:block font-size="10pt">
        <xsl:value-of select="."/>
    </fo:block>
</xsl:template>

</xsl:stylesheet>

更新:我检查了两台机器上的 XSLT 进程,它们是相同的。我还将两台机器上的 XML + XSL 转换为 XLS:FO,并且两个文件是相同的。


我使用你的 XML 和 XSL 文件

C:\Users\User>cd Documents
C:\Users\User\Documents>cd fop-1.0
C:\Users\User\Documents\fop-1.0>fop -xsl stovfl17548663.xsl -xml stovfl17548663.xml -pdf stovfl17548663.pdf

我收到以下消息

C:\Users\User\Documents\fop-1.0>fop -xsl stovfl17548663.xsl -xml stovfl17548663.xml -pdf stovfl17548663.pdf
Sep 26, 2013 12:09:47 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
Sep 26, 2013 12:09:47 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "ZapfDingbats,normal,700" not found. Substituting with    "ZapfDingbats,normal,400".
Sep 26, 2013 12:09:48 PM org.apache.fop.events.LoggingEventListener processEvent
SEVERE: Image not found. URI: graphs/graph1.png. (No context info available)
Sep 26, 2013 12:09:48 PM org.apache.fop.events.LoggingEventListener processEvent
SEVERE: Image not found. URI: graphs/graph1.png. (No context info available)
Sep 26, 2013 12:09:48 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: 1 link target could not be fully resolved and now point to the top of the page or is dysfunctional.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法使用 Apache FOP 生成 PDF 的相关文章

随机推荐

  • HttpURLConnection.getInputStream 非常慢

    与使用相同服务器端服务的 iPhone 应用程序相比 HttpURLConnection getInputStream 需要花费很多时间 以下代码用于该服务 date new java util Date Log d time Time S
  • DSP——获取所有频率的幅度

    这个问题与 DSP 音频处理 squart还是log来利用fft https stackoverflow com questions 20057831 dsp audio processing squart or log to levera
  • 标准程序的用途列表

    我正在搜索 SAP 表的使用 我想知道桌子在哪里S083用于 SAP 标准程序 我已经搜索过 使用地点 列表 但我只得到了自创程序 没有得到SAP标准程序 有人知道如何在 SAP 标准程序中搜索表使用吗 为了能够使用 SAP 标准编码的使用
  • 如何选择列值以特定字符串开头的行?

    如何选择列值以特定字符串开头的行 例如 我想选择 姓名 列以 先生 开头的行 你可以做 select from mytable where name like Mr See http www sqlite org lang expr htm
  • 无法在 Maven 插件上使用注释设置参数

    我正在尝试开发一个 Maven 插件 但当我使用 Parameter 注释时它不起作用 我的依赖项
  • 图像地图区域聚某些坐标 Firefox 不起作用,IE 起作用

    我遇到了图像映射 HTML 问题 没有样式和 js 的工作示例 http www download lagunawebdesign pl bug http www download lagunawebdesign pl bug img sr
  • 如何在spark中配置hbase?

    Spark连接hbase的步骤是什么 我有两者的主地址 我是否只需将 hbase 地址添加到 Spark 类路径中 这篇关于 Spark 与 HBase 连接的文章应该会有所帮助 http www vidyasource com blog
  • 没有唯一标识符的 Bootstrap 崩溃

    我正在尝试以不需要唯一标识符的方式使用引导折叠插件 通常 页面上通常有一个或几个可折叠元素 但我的元素是动态生成的 传递索引键是多余的 现在发生的情况是 如果我将折叠切换为element2 它会崩溃element1 显然是因为他们有相同的I
  • 优先连接Wifi [无互联网]?

    我有个问题 我开发了一个android应用程序 它也应该连接到无线网络 没有互联网 只是为了控制机器人 网页界面 10 10 0 1 我的问题 如果我连接到机器人 wifi Android 会阻止连接并连接到我的默认家庭 WLAN 我可以更
  • 如何在应用程序中禁用 Aero Snap?

    是否可以在 WPF 应用程序中禁用 Windows 7 的自动窗口停靠功能 我最近需要对一个自定义的 可调整大小的ResizeMode CanResizeWithGrip没有窗口装饰的 WPF 窗口 没有标题栏和按钮 我用了DragMove
  • 如何在 iOS 7 应用程序上启用后台更新

    如何让我的应用程序使用 iOS 7 后台更新功能 我注意到一些应用程序已经做到了这一点 但似乎并不是所有应用程序都是自动的 根据iOS 7 的新功能 https developer apple com library ios release
  • 是否可以在 Chrome 检查器中过滤选项请求?

    我正在构建一个使用 CORS 与其服务器进行通信的 Web 应用程序 这意味着每个请求之前都有一个带有 OPTIONS 方法的请求 是否可以在检查器中过滤掉它们 它在网络选项卡上造成了很多不必要的混乱 是的 您可以使用 method OPT
  • 属性错误:“用户”对象没有属性“is_admin”

    我通过扩展 AbstractBaseUser 自定义了用户模型 用户名仅接受电子邮件 ID 这是模型 class User AbstractBaseUser PermissionsMixin email models EmailField
  • 修改包含数据的列类型,而不删除数据

    我有一个专栏 我认为该专栏的声明是错误的 它包含数据 我不希望丢失数据 我希望将定义从 varchar max 更改为 varchar 整数 我的印象是我不能只改变列类型 最好的方法是创建临时列 column2 将数据从有问题类型的列传输到
  • Subversion 更新问题

    当我尝试更新我的存储库时 出现以下错误 有人能解释一下这是什么意思吗 命令 更新错误 网址错误 http mysvn foo 错误 现有目录错误 C SVN MyProj NinjectModules Models 不匹配错误 预期 URL
  • 保留 SQL 中的文本格式

    我有一个文本区域 可将其内容插入到 SQL 表中 有没有办法保留文本的格式 然后在 HTML 中使用它 我假设您正在谈论保留换行符 Either 输出 标签内的文本 or 在插入数据库之前将换行符转换为 标记 例如 PHP 中的 nl2br
  • R 噩梦:Yosemite、R、RStudio 和 Homebrew

    我使用配备 OS X Yosemite 10 10 2 的 MacBook Pro 13 Retina 2013 年末 我不希望我最大的敌人遇到这种情况 也许吧 噩梦按时间顺序排列 从官方网站下载 R 和 RStudio 运行这两个应用程序
  • 将数组数据分解为spark中的行[重复]

    这个问题在这里已经有答案了 我有一个数据集 如下所示 FieldA FieldB ArrayField 1 A 1 2 3 2 B 3 5 我想爆炸数据数组字段所以输出将如下所示 FieldA FieldB ExplodedField 1
  • 提高 Python Tesseract OCR 的准确性

    我在用pytesseract https pypi org project pytesseract 随着openCV https pypi org project opencv python 在 Python 中的简单 django 应用程
  • 无法使用 Apache FOP 生成 PDF

    我正在尝试使用 Apache FOP 使用 XML 数据和 XSL 样式表创建 PDF 但我不断收到以下错误 org apache fop apps FOPException org apache fop fo ValidationExce