[英]How to repeat same template in table-row using XSL-FO/Apache FOP
[英]How to detect overflow or line breaks in XSL-FO document rendered with Apache FOP
我有一个非常简单的FO文档:
<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="A4">
<fo:region-body margin-top="30mm" />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4">
<fo:flow flow-name="xsl-region-body">
<fo:block-container height="10mm" font-size="8mm" overflow="error-if-overflow" wrap-option="wrap">
<fo:block wrap-option="wrap">Hello W3Schools Hello W3Schools Hello W3Schools sad da sadasd dsaasd</fo:block>
</fo:block-container>
</fo:flow>
</fo:page-sequence>
</fo:root>
将overflow
设置为error-if-overflow
,呈现此文档时会出错。 有什么方法可以检测文本中的溢出位置? 我希望能够手动将文本分成多部分,但是我不希望一次删除一个单词并重新运行渲染以查看其是否再次失败的想法。
得到的异常是:
Content overflows the viewport of an fo:block-container in block-progression direction by 26078 millipoints. Content will be clipped. (See position 12:103)
不幸的是,这是发生错误的block-container
标签的位置,而不是造成溢出的特定单词。
您可以使用FOP的“中间格式”功能来创建生成的页面和区域的XML表示 ,而不是创建PDF输出。
然后,您可以将其用作输入
您可以使用以下命令从命令行创建区域树(AT)输出
fop input.fo -at application/pdf at.xml
或者您可以使用创建中间格式(IF)输出
fop input.fo -if application/pdf if.xml
( FOP的站点上有有关如何使用Java代码以编程方式产生中间格式输出的详细信息)。
例如,如果您输入的FO文件包含
<!--
there is no need for the wrap-option="wrap" attributes, as that is the default value,
I added an id attribute on the fo:block-container
-->
<fo:block-container id="foo" height="10mm" font-size="8mm" overflow="error-if-overflow">
<fo:block>Hello W3Schools Hello W3Schools Hello W3Schools sad da sadasd dsaasd</fo:block>
</fo:block-container>
IF输出(比AT的输出少一些)是这样的:
...
<page index="0" name="1" page-master-name="A4" width="594720" height="792000">
<page-header/>
<content>
<viewport transform="translate(0,85039)" width="594720" height="706961">
<viewport width="594720" height="28346" clip-rect="0 0 594720 28346">
<font family="sans-serif" style="normal" weight="400" variant="normal" size="22677" color="#000000"/>
<id name="foo"/>
<text x="0" y="19400">Hello W3Schools Hello W3Schools Hello W3Schools sad</text>
<text x="0" y="46612">da sadasd dsaasd</text>
</viewport>
</viewport>
</content>
<page-trailer/>
</page>
...
XPath //viewport[id[@name = 'foo']]/text[1]
为您提供第一行的文本内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.