我刚接触XSLT FO世界,遇到了一个问题。我的XSLT与fop-0.95处理器配合良好,可以生成PDF,但在我升级到fop-2.3之后,它将我的第一页保留为空白,并从第二页开始创建PDF正文(我的PDF有一个标题,在第一页上看起来很好)。
我发现了问题所在,这是因为我在fo:布局-主控集内的“fo:区域-身体”标签中将边距-顶部
值设置为3英寸(请看屏幕截图)。我必须将边距-顶部
从3英寸更改为2.5英寸,以便我的PDF正文在使用fop-0.95时看起来像是这样。
<?xml version="1.0" encoding="UTF-8"?>
<!--Designed and generated by Altova StyleVision Enterprise Edition 2013 (x64) - see http://www.altova.com/stylevision for more information.-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:altova="http://www.altova.com" xmlns:altovaext="http://www.altova.com/xslt-extensions" xmlns:clitype="clitype" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:iso4217="http://www.xbrl.org/2003/iso4217" xmlns:ix="http://www.xbrl.org/2008/inlineXBRL" xmlns:java="java" xmlns:link="http://www.xbrl.org/2003/linkbase" xmlns:sps="http://www.altova.com/StyleVision/user-xpath-functions" xmlns:xbrldi="http://xbrl.org/2006/xbrldi" xmlns:xbrli="http://www.xbrl.org/2003/instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg" exclude-result-prefixes="altova altovaext clitype fn iso4217 ix java link sps xbrldi xbrli xlink xs xsi">
<xsl:output version="1.0" method="xml" encoding="UTF-8" indent="no"/>
<xsl:param name="SV_OutputFormat" select="'PDF'"/>
<xsl:variable name="XML" select="/"/>
<xsl:variable name="fo:layout-master-set">
<fo:layout-master-set>
<fo:simple-page-master master-name="page-master-0-even" margin-left="0.50in" margin-right="0.50in" page-height="11in" page-width="8.50in" margin-top="0.30in" margin-bottom="0.30in">
<fo:region-body margin-top="0.45in" margin-bottom="0.45in" column-count="1" column-gap="0.50in"/>
<fo:region-before region-name="even-page-header" overflow="hidden" extent="0.45in"/>
<fo:region-after region-name="even-page-footer" overflow="hidden" extent="0.45in"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="page-master-0-odd" margin-left="0.50in" margin-right="0.50in" page-height="11in" page-width="8.50in" margin-top="0.30in" margin-bottom="0.30in">
<fo:region-body margin-top="0.45in" margin-bottom="0.45in" column-count="1" column-gap="0.50in"/>
<fo:region-before region-name="odd-page-header" overflow="hidden" extent="0.45in"/>
<fo:region-after region-name="odd-page-footer" overflow="hidden" extent="0.45in"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="page-master-0-even-first" margin-left="0.50in" margin-right="0.50in" page-height="11in" page-width="8.50in" margin-top="0.30in" margin-bottom="0.30in">
<fo:region-body margin-top="3in" margin-bottom="0.45in" column-count="1" column-gap="0.50in"/>
<fo:region-before region-name="even-page-header-first" overflow="hidden" extent="3in"/>
<fo:region-after region-name="even-page-footer" overflow="hidden" extent="0.45in"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="page-master-0-odd-first" margin-left="0.50in" margin-right="0.50in" page-height="11in" page-width="8.50in" margin-top="0.30in" margin-bottom="0.30in">
<fo:region-body margin-top="3in" margin-bottom="0.45in" column-count="1" column-gap="0.50in"/>
<fo:region-before region-name="odd-page-header-first" overflow="hidden" extent="3in"/>
<fo:region-after region-name="odd-page-footer" overflow="hidden" extent="0.45in"/>
</fo:simple-page-master>
<fo:page-sequence-master master-name="page-master-0">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference master-reference="page-master-0-even-first" odd-or-even="even" page-position="first"/>
<fo:conditional-page-master-reference master-reference="page-master-0-odd-first" odd-or-even="odd" page-position="first"/>
<fo:conditional-page-master-reference master-reference="page-master-0-even" odd-or-even="even"/>
<fo:conditional-page-master-reference master-reference="page-master-0-odd" odd-or-even="odd"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>
</xsl:variable>
<xsl:variable name="altova:nPxPerIn" select="96"/>
<xsl:template match="/">
<fo:root>
<xsl:copy-of select="$fo:layout-master-set"/>
<fo:declarations>
<x:xmpmeta xmlns:x="adobe:ns:meta/">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">
<xmp:CreatorTool>Altova StyleVision Enterprise Edition 2013 (x64) (http://www.altova.com)</xmp:CreatorTool>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
</fo:declarations>
<fo:page-sequence force-page-count="no-force" master-reference="page-master-0" initial-page-number="auto" format="1">
<fo:static-content flow-name="odd-page-header-first">
<fo:block-container overflow="hidden" display-align="before">
<fo:block>
<xsl:for-each select="$XML">
<xsl:for-each select="DOCUMENT">
<xsl:for-each select="DATA">
<xsl:for-each select="STRUCT">
<xsl:for-each select="FIELD[FNAME='nfHeaderDtls']">
<xsl:for-each select="STRUCT">
<fo:block-container font-family="Arial" font-size="10pt" width="7.490000in" height="3.000000in" overflow="hidden">
<fo:block-container absolute-position="absolute" font-family="Arial" font-size="9pt" height="1.21in" left="4.55in" top="1.75in" width="2.90in" overflow="hidden">
<fo:block>
<xsl:for-each select="FIELD[FNAME='Name']">
<xsl:for-each select="VALUE">
<xsl:variable name="value-of-template_1">
<xsl:apply-templates/>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains(string($value-of-template_1),'​')">
<fo:block>
<xsl:copy-of select="$value-of-template_1"/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:inline>
<xsl:copy-of select="$value-of-template_1"/>
</fo:inline>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
<fo:block/>
</fo:block>
</fo:block-container>
</fo:block-container>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</fo:block>
</fo:block-container>
</fo:static-content>
<fo:static-content flow-name="even-page-header-first">
<fo:block-container overflow="hidden" display-align="before">
<fo:block>
<xsl:for-each select="$XML">
<xsl:for-each select="DOCUMENT">
<xsl:for-each select="DATA">
<xsl:for-each select="STRUCT">
<xsl:for-each select="FIELD[FNAME='nfHeaderDtls']">
<xsl:for-each select="STRUCT">
<fo:block-container font-family="Arial" font-size="10pt" width="7.490000in" height="3.000000in" overflow="hidden">
<fo:block-container absolute-position="absolute" font-family="Arial" font-size="9pt" height="1.21in" left="4.55in" top="1.75in" width="2.90in" overflow="hidden">
<fo:block>
<xsl:for-each select="FIELD[FNAME='Name']">
<xsl:for-each select="VALUE">
<xsl:variable name="value-of-template_1">
<xsl:apply-templates/>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains(string($value-of-template_1),'​')">
<fo:block>
<xsl:copy-of select="$value-of-template_1"/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:inline>
<xsl:copy-of select="$value-of-template_1"/>
</fo:inline>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
<fo:block/>
</fo:block>
</fo:block-container>
</fo:block-container>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</fo:block>
</fo:block-container>
</fo:static-content>
<fo:static-content flow-name="odd-page-header">
<fo:block-container overflow="hidden" display-align="before">
<fo:block>
<xsl:for-each select="$XML">
<xsl:for-each select="DOCUMENT">
<xsl:for-each select="DATA">
<xsl:for-each select="STRUCT">
<xsl:for-each select="FIELD[FNAME='nfHeaderDtls']">
<xsl:for-each select="STRUCT">
<fo:block-container font-family="Arial" font-size="10pt" width="7.500000in" height="0.500000in" overflow="hidden">
<fo:block-container absolute-position="absolute" height="0.19in" left="0in" top="0in" width="2.78in" overflow="hidden">
<fo:block>
<fo:inline>
<xsl:text>Identifier: </xsl:text>
</fo:inline>
<xsl:for-each select="FIELD[FNAME='caseReference']">
<xsl:for-each select="VALUE">
<xsl:variable name="value-of-template_27">
<xsl:apply-templates/>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains(string($value-of-template_27),'​')">
<fo:block>
<xsl:copy-of select="$value-of-template_27"/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:inline>
<xsl:copy-of select="$value-of-template_27"/>
</fo:inline>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</fo:block>
</fo:block-container>
</fo:block-container>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</fo:block>
</fo:block-container>
</fo:static-content>
<fo:static-content flow-name="even-page-header">
<fo:block-container overflow="hidden" display-align="before">
<fo:block>
<xsl:for-each select="$XML">
<xsl:for-each select="DOCUMENT">
<xsl:for-each select="DATA">
<xsl:for-each select="STRUCT">
<xsl:for-each select="FIELD[FNAME='nfHeaderDtls']">
<xsl:for-each select="STRUCT">
<fo:block-container font-family="Arial" font-size="10pt" width="7.500000in" height="0.500000in" overflow="hidden">
<fo:block-container absolute-position="absolute" height="0.19in" left="0in" top="0in" width="2.78in" overflow="hidden">
<fo:block>
<fo:inline>
<xsl:text>Identifier: </xsl:text>
</fo:inline>
<xsl:for-each select="FIELD[FNAME='caseReference']">
<xsl:for-each select="VALUE">
<xsl:variable name="value-of-template_27">
<xsl:apply-templates/>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains(string($value-of-template_27),'​')">
<fo:block>
<xsl:copy-of select="$value-of-template_27"/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:inline>
<xsl:copy-of select="$value-of-template_27"/>
</fo:inline>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</fo:block>
</fo:block-container>
</fo:block-container>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</fo:block>
</fo:block-container>
</fo:static-content>
<fo:static-content flow-name="odd-page-footer">
<fo:block-container height="0.45in" overflow="hidden" display-align="after">
<fo:block>
<fo:block-container font-family="Arial" font-size="10pt" width="7.490000in" height="0.500000in" overflow="hidden">
<fo:block-container absolute-position="absolute" height="0.40in" left="0in" top="0in" width="4.04in" overflow="hidden">
<fo:block>
<fo:inline>
<xsl:text>My Test Form</xsl:text>
</fo:inline>
<fo:block/>
<fo:inline>
<xsl:text>Test Text</xsl:text>
</fo:inline>
</fo:block>
</fo:block-container>
<fo:block-container absolute-position="absolute" height="0.38in" left="4.82in" text-align="right" top="0in" width="2.63in" overflow="hidden">
<fo:block>
<fo:inline font-weight="bold">
<xsl:text>Page: </xsl:text>
</fo:inline>
<fo:page-number font-weight="bold"/>
<fo:inline font-weight="bold">
<xsl:text> of </xsl:text>
</fo:inline>
<fo:page-number-citation ref-id="SV_RefID_PageTotal" font-weight="bold"/>
</fo:block>
</fo:block-container>
</fo:block-container>
</fo:block>
</fo:block-container>
</fo:static-content>
<fo:static-content flow-name="even-page-footer">
<fo:block-container height="0.45in" overflow="hidden" display-align="after">
<fo:block>
<fo:block-container font-family="Arial" font-size="10pt" width="7.490000in" height="0.500000in" overflow="hidden">
<fo:block-container absolute-position="absolute" height="0.40in" left="0in" top="0in" width="4.04in" overflow="hidden">
<fo:block>
<fo:inline>
<xsl:text>My Test Form</xsl:text>
</fo:inline>
<fo:block/>
<fo:inline>
<xsl:text>Test Text</xsl:text>
</fo:inline>
</fo:block>
</fo:block-container>
<fo:block-container absolute-position="absolute" height="0.38in" left="4.82in" text-align="right" top="0in" width="2.63in" overflow="hidden">
<fo:block>
<fo:inline font-weight="bold">
<xsl:text>Page: </xsl:text>
</fo:inline>
<fo:page-number font-weight="bold"/>
<fo:inline font-weight="bold">
<xsl:text> of </xsl:text>
</fo:inline>
<fo:page-number-citation ref-id="SV_RefID_PageTotal" font-weight="bold"/>
</fo:block>
</fo:block-container>
</fo:block-container>
</fo:block>
</fo:block-container>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:block>
<xsl:for-each select="$XML">
<xsl:for-each select="DOCUMENT">
<xsl:for-each select="DATA">
<xsl:for-each select="STRUCT">
<fo:block-container font-family="Arial" font-size="10pt" width="7.500000in" height="7.040000in" overflow="hidden">
<fo:block-container absolute-position="absolute" font-family="Arial" font-size="13pt" font-weight="bold" height="0.28in" left="0in" text-align="center" top="0in" width="7.46in" overflow="hidden">
<fo:block>
<fo:inline>
<xsl:text>Form Body Starts Here </xsl:text>
</fo:inline>
<xsl:for-each select="FIELD[FNAME='nfFormTitle']">
<xsl:for-each select="VALUE">
<xsl:variable name="value-of-template_28">
<xsl:apply-templates/>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains(string($value-of-template_28),'​')">
<fo:block>
<xsl:copy-of select="$value-of-template_28"/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:inline>
<xsl:copy-of select="$value-of-template_28"/>
</fo:inline>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
<fo:inline>
<xsl:text> Test Test</xsl:text>
</fo:inline>
</fo:block>
</fo:block-container>
</fo:block-container>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</fo:block>
<fo:block id="SV_RefID_PageTotal"/>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template name="altova:double-backslash">
<xsl:param name="text"/>
<xsl:param name="text-length"/>
<xsl:variable name="text-after-bs" select="substring-after($text, '\')"/>
<xsl:variable name="text-after-bs-length" select="string-length($text-after-bs)"/>
<xsl:choose>
<xsl:when test="$text-after-bs-length = 0">
<xsl:choose>
<xsl:when test="substring($text, $text-length) = '\'">
<xsl:value-of select="concat(substring($text,1,$text-length - 1), '\\')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(substring($text,1,$text-length - $text-after-bs-length - 1), '\\')"/>
<xsl:call-template name="altova:double-backslash">
<xsl:with-param name="text" select="$text-after-bs"/>
<xsl:with-param name="text-length" select="$text-after-bs-length"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="altova:MakeValueAbsoluteIfPixels">
<xsl:param name="sValue"/>
<xsl:variable name="sBeforePx" select="substring-before($sValue, 'px')"/>
<xsl:choose>
<xsl:when test="$sBeforePx">
<xsl:variable name="nLengthOfInteger">
<xsl:call-template name="altova:GetCharCountOfIntegerAtEndOfString">
<xsl:with-param name="sText" select="$sBeforePx"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="nPosOfInteger" select="string-length($sBeforePx) - $nLengthOfInteger + 1"/>
<xsl:variable name="nValuePx" select="substring($sBeforePx, $nPosOfInteger)"/>
<xsl:variable name="nValueIn" select="number($nValuePx) div number($altova:nPxPerIn)"/>
<xsl:variable name="nLengthBeforeInteger" select="string-length($sBeforePx) - $nLengthOfInteger"/>
<xsl:variable name="sRest">
<xsl:call-template name="altova:MakeValueAbsoluteIfPixels">
<xsl:with-param name="sValue" select="substring-after($sValue, 'px')"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="concat(substring($sBeforePx, 1, $nLengthBeforeInteger), string($nValueIn), 'in', $sRest)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$sValue"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="altova:GetCharCountOfIntegerAtEndOfString">
<xsl:param name="sText"/>
<xsl:variable name="sLen" select="string-length($sText)"/>
<xsl:variable name="cLast" select="substring($sText, $sLen)"/>
<xsl:choose>
<xsl:when test="number($cLast) >= 0 and number($cLast) <= 9">
<xsl:variable name="nResultOfRest">
<xsl:call-template name="altova:GetCharCountOfIntegerAtEndOfString">
<xsl:with-param name="sText" select="substring($sText, 1, $sLen - 1)"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$nResultOfRest + 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>0</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
有人知道为什么会发生这种情况吗?
我有多个布局相同的PDF,所以如果我需要升级到fop-2.3,我必须对我所有的PDF进行此更改吗?
编辑-1.感谢您的评论和回答。很抱歉,我花了一段时间才回复,因为我正在努力获得发布此xslt的批准。
2.我编辑了xslt,因为它太大了,不符合这篇文章的字数限制。但是它仍然有所有重要的部分,如PDF正文的开头等。
抱歉,要弄清楚为什么同一软件的不同版本之间存在差异,最好的方法是查看自旧版本以来发布的发行说明。
FOP在其网站上有发布说明。当我确认时,我在https://xmlgraphics.apache.org/fop/1.0/changes_1.0.html,这可能是您正在寻找的:
启用轻松验证时,允许页面区域上的非零边框和填充。由LF提交。
如果这是原因,那么解决方案是从fo: simle-page-master
中删除边顶
。否则,恐怕还有很多发行说明需要您查看。
我已经将FOP版本从fop 1.1升级到fop 2.3,但是 org.apache.fop.events。未找到LoggingEventListener processEvent Image。 以下是为升级而修改的代码片段。使用fop 2.3主控查看代码 法典: 查看fop 2.3的代码 XSLT 代码
我有3个SVG文件,我想转换成一个PDF。我正试图用Apache FOP实现这一点,但迄今为止我没有成功。 我的想法是简单地将所有3个SVG文件一个接一个地写入生成的PDF中,但是这不起作用。我的代码是这样的: 最后,我的SVG图像如下所示,它们是由javascript应用程序生成的。 到目前为止,我的代码覆盖了pdf两次,生成的PDF只包含最后一个SVG。我也可以用里面的图像创建3个单独的pdf
我在将FOP从2.2版迁移/升级到2.3版时遇到了一个问题。分页器停止工作…这是示例代码: 主要“模板”: 寻呼机1: 分页器2: 我得到的错误是: 严重:序列化页面1时出错。原因:java.io。NotSerializableException:org.apache.fop.fo.pagination。PageSequence java.io。NotSerializableException:o
WARNING 本升级指南仅适用于 2.2 版本升级至 2.3 版本,如果你并非 2.2 版本,请查看其他升级指南,Plus 程序不允许跨版本升级! 更新代码 预计耗时: 2 小时 这是你自我操作的步骤,确认将你的 2.2 版本代码升级到 2.3 版本,如果你做过一些自定义修改可能会出现代码冲突,你需要解决。 升级依赖 预计耗时: 3 分钟 进入 Plus 程序目录,执行: composer up
我有以下场景: 我有一个没有表单字段的PDF文档。然而,PDF文档有点像一封正式信函,其中的各个部分都需要精确地“套印”。 这可以用FOP和自定义XSLT样式表完成吗? 杰森
FOP是由James Tauber发起的一个开源项目,原先的版本是利用xsl-fo将xml文件转换成pdf文件。但最新的版本它可以将xml文件转换成pdf,mif,pcl,txt等多种格式以及直接输出到打印机,并且支持使用SVG描述图形。