将所有格式设置在最上面的块中是否可以提高pdf生成的性能



我有一个xslfo代码来生成pdfs,我正在使用Apache FOP来实现这一点。在每个块中,我都提到了格式化对象,例如字体系列和大小。我可以在不降低性能的情况下将其移动到fo:block的顶部吗?

电流来源:

<fo:block widows="2" orphans="2" font-size="10pt" line-height="1.147" white-space-collapse="false">
                    <fo:block space-after="8pt" space-after.conditionality="retain" line-height="1.2378041666666666" font-family="TimesNewRoman" font-size="11pt" text-align="center">
                        <fo:inline font-family="TimesNewRoman" font-weight="bold" font-size="14pt">
                            <fo:leader leader-length="0pt" />Some Title
                        </fo:inline>
                    </fo:block>
    <fo:block space-after="8pt" space-after.conditionality="retain" line-height="1.2378041666666666" font-family="TimesNewRoman" font-size="11pt" text-align="center">
                            <fo:inline font-family="TimesNewRoman" font-weight="bold" font-size="14pt">
                                <fo:leader leader-length="0pt" />Some Other Title
                            </fo:inline>
                        </fo:block>
    </fo:block>

想要更改为:

<fo:block widows="2" orphans="2" line-height="1.147" white-space-collapse="false" font-family="TimesNewRoman" font-size="11pt">
                        <fo:block space-after="8pt" space-after.conditionality="retain" line-height="1.2378041666666666" text-align="center">
                            <fo:inline font-family="TimesNewRoman" font-weight="bold" font-size="14pt">
                                <fo:leader leader-length="0pt" />Some Title
                            </fo:inline>
                        </fo:block>
        <fo:block space-after="8pt" space-after.conditionality="retain" line-height="1.2378041666666666" text-align="center">
                                <fo:inline font-family="TimesNewRoman" font-weight="bold" font-size="14pt">
                                    <fo:leader leader-length="0pt" />Some Other Title
                                </fo:inline>
                            </fo:block>
        </fo:block>

很抱歉代码格式不正确。我需要优先考虑文件的生成速度。两者中哪一个更好?

作为了解其中一个引擎内部结构的人,答案是"非常非常小"。大多数引擎都在创建一个内部的格式化结果树,用于解析所有继承。在这个表示中,您在每个元素上指定为继承或完全继承的所有内容都将消失。

话虽如此。在创建它的过程中,会创建并比较节点,XML+XSL到XSL-FO的转换会占用所有这些节点的内存和空间。

因此,例如,在每个元素上指定字体系列(作为相同的字体系列)可能会在引擎内部解析为引擎中间格式中的一个字体开关,但分析并执行这一操作当然需要时间和内存

多少钱?

最小。要花更多的时间来决定字母的拼写、双向、什么适合一行、在页尾做什么、把什么放在一起等等。

我的猜测。0.5%。如果使用XML+XSL,读取较大的XSL-FO文件或在内存中创建它们会产生更大的影响。更多的内存就是全部。它会影响性能,但影响很小。

将表放在表中,并使用keeps和continued headers=20+%。或者选择一个像Arial Unicode这样的巨大字体,并像一个子弹一样要求从中选择一个字符。

最新更新