有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Apache FOP fox:使用PDF文件时外部文档不工作

我试图使用Apache FOPfox:external-document附加pdf文档,但在使用pdf类型时引发以下异常:

SEVERE: Image not available. URI: /pathToPdf/file.pdf. Reason: org.apache.xmlgraphics.image.loader.ImageException: The file format is not supported. No ImagePreloader found for /pathToPdf/file.pdf (See position 202:89)
org.apache.xmlgraphics.image.loader.ImageException: The file format is not supported. No ImagePreloader found for /pathToPdf/file.pdf
<?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" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
    <xsl:template match="/">
        <fo:root>
            <fo:layout-master-set>
                ...
            </fo:layout-master-set>            

            <fox:external-document content-type="pdf" src="/pathToPdf/file.pdf"/>
        </fo:root>
    </xsl:template>
</xsl:stylesheet>

我正在使用ApacheFop2.3和Java8


共 (2) 个答案

  1. # 1 楼答案

    扩展属性^{}最初用于在pdf输出中插入图像作为页面

    为了与pdf文件一起使用,您需要PDF Images Plug-In

    只需下载并将jar放在lib文件夹中(或链接),一切都会按照您的预期工作

  2. # 2 楼答案

    从文件系统或资源添加pdf时对我来说工作正常:

    Filesystem:
    <fox:external-document src="url('file:D:///resource/test.pdf')"/>
    Resource:
    <fox:external-document src="url('file:resource/test.pdf')"/> 
    
    Remember to add:
      xmlns:pdf="http://xmlgraphics.apache.org/fop/extensions/pdf"
    and 
      xmlns:fox="http://xmlgraphics.apache.org/fop/extensions"