由于Java堆空间内存错误,无法处理巨大数据的PDF转换(XSLFO到PDF)。
使用FOP1.1、xalan-2.7.1、xercesImpl-2.9.0、serializer-2.9.1 jar进行此过程。Windows操作系统是32位的。为这个进程分配的JVM空间是-Xmx1500M。
有没有其他方法可以提高下面xsl-fo代码的性能?有没有更好的pdf呈现jar可用。。请帮忙。
<fo:table-body>
<xsl:for-each select="MSISDN/ITEM/CALLSUM">
<fo:table-row>
<fo:table-cell padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" display-align="before" width="264.33pt" reference-orientation="0">
<fo:block-container reference-orientation="0" >
<fo:block keep-together="auto" ><!-- GENERATE TABLE START-->
<xsl:message>before if</xsl:message>
<xsl:apply-templates match="CALLS[position() mod 2 != 0]"/>
</fo:block>
</fo:block-container>
</fo:table-cell>
<fo:table-cell>
<fo:block-container reference-orientation="0" >
<fo:block keep-together="auto" >
<xsl:apply-templates match="CALLS[position() mod 2 =0]"/>
</fo:block>
</fo:block-container>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
<xsl:template match="CALLS[position() mod 2 !=0 ]">
<fo:table table-layout="fixed" width="100%">
<fo:table-column column-width="56.05pt"/>
<fo:table-column column-width="18.0pt"/>
<fo:table-column column-width="71.0pt"/>
<fo:table-column column-width="45.52pt"/>
<fo:table-column column-width="48.37pt"/>
<fo:table-column column-width="25.47pt"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" display-align="before" width="56.05pt" reference-orientation="0">
<fo:block-container>
<fo:block linefeed-treatment="preserve" white-space-treatment="ignore-if-surrounding-linefeed" padding-bottom="0.0pt" start-indent="1.42pt" end-indent="0.0pt" padding-top="0.0pt" line-height="7.199999999999999pt" line-stacking-strategy="max-height" white-space-collapse="false" hyphenate="true" language="en" text-align="start" keep-together="auto" color="#000000" font-family="Arial" font-size="6.0pt" letter-spacing="normal" word-spacing="normal">
<fo:inline color="#000000" font-family="Arial" font-size="6.0pt">
<xsl:value-of disable-output-escaping="no" select="@OPN"/>
</fo:inline>
</fo:block>
</fo:block-container>
</fo:table-cell>
<fo:table-cell padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" display-align="before" width="48.37pt" reference-orientation="0">
<fo:block-container>
<fo:block linefeed-treatment="preserve" white-space-treatment="ignore-if-surrounding-linefeed" padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" line-height="7.199999999999999pt" line-stacking-strategy="max-height" white-space-collapse="false" hyphenate="true" language="en" text-align="start" keep-together="auto" color="#000000" font-family="Arial" font-size="6.0pt" letter-spacing="normal" word-spacing="normal">
<fo:inline color="#000000" font-family="Arial" font-size="6.0pt">
<xsl:value-of disable-output-escaping="no" select="@CALL_TYPE"/>
</fo:inline>
</fo:block>
</fo:block-container>
</fo:table-cell>
<fo:table-cell padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" display-align="before" width="57.0pt" reference-orientation="0">
<fo:block-container>
<fo:block linefeed-treatment="preserve" white-space-treatment="ignore-if-surrounding-linefeed" padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" line-height="7.199999999999999pt" line-stacking-strategy="max-height" white-space-collapse="false" hyphenate="true" language="en" text-align="center" keep-together="auto" color="#000000" font-family="Arial" font-size="6.0pt" letter-spacing="normal" word-spacing="normal">
<fo:inline color="#000000" font-family="Arial" font-size="6.0pt">
<xsl:value-of disable-output-escaping="no" select="@DT"/>
</fo:inline>
</fo:block>
</fo:block-container>
</fo:table-cell>
<fo:table-cell padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" display-align="before" width="51.21pt" reference-orientation="0">
<fo:block-container>
<fo:block linefeed-treatment="preserve" white-space-treatment="ignore-if-surrounding-linefeed" padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" line-height="7.199999999999999pt" line-stacking-strategy="max-height" white-space-collapse="false" hyphenate="true" language="en" text-align="center" keep-together="auto" color="#000000" font-family="Arial" font-size="6.0pt" letter-spacing="normal" word-spacing="normal">
<fo:inline color="#000000" font-family="Arial" font-size="6.0pt">
<xsl:value-of disable-output-escaping="no" select="@BILLDUR"/>
</fo:inline>
</fo:block>
</fo:block-container>
</fo:table-cell>
<fo:table-cell border-right-style="solid" border-right-width="0.57pt" border-right-color="#000000" padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" display-align="before" width="31.3pt" reference-orientation="0">
<fo:block-container>
<fo:block linefeed-treatment="preserve" white-space-treatment="ignore-if-surrounding-linefeed" padding-bottom="0.0pt" start-indent="0.0pt" end-indent="0.0pt" padding-top="0.0pt" padding="0.0pt" line-height="7.199999999999999pt" line-stacking-strategy="max-height" white-space-collapse="false" hyphenate="true" language="en" text-align="start" keep-together="auto" color="#000000" font-family="Arial" font-size="6.0pt" letter-spacing="normal" word-spacing="normal">
<fo:inline color="#000000" font-family="Arial" font-size="6.0pt">
<xsl:value-of disable-output-escaping="no" select="@AMT"/>
</fo:inline>
</fo:block>
</fo:block-container>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</xsl:template>
我无法想象xsl-fo代码优化可以节省足够的内存,问题似乎是数据量。也许另一个渲染器可以让你摆脱这种状态。您可以从alt soft尝试Xml2PDF,它是免费的,适用于Windows。看见http://www.alt-soft.com/index/products/xml2pdf-workstation/
- 不显示外表使用固定宽度还是自动宽度
- 如果你不包括所有默认值或继承值的属性,你可能会在内存方面做得更好
- 看起来您的子表每个都有六列宽和一行深。为什么不使用六列(实际上,当前两列都有12列)呢?如果CALL的数量可能是奇数,但你更有可能让你的桌子正常工作,你就必须添加更多的逻辑
- 你可能必须使用商业FO处理器,例如Antenna House,但他们通常会让你有试用许可证,这样你就可以在支付软件费用之前看看他们是否能满足你的需求
为了提高XSL的性能,请避免使用XSL:for-each,并将其替换为应用模板。
<table-body>
<xsl:apply-templates select="MSISDN/ITEM/CALLSUM"/>
</table-body>
<xsl:template match="CALLSUM">
<!-- The content of the template -->
</xsl:template>