如何在用 XSL-FO 生成的 PDF 中插入换行符 [英] How to insert line breaks in a PDF generated with XSL-FO

查看:30
本文介绍了如何在用 XSL-FO 生成的 PDF 中插入换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 XSL-FO 和 XML 生成 PDF.在文本框中,用户可以输入像1"这样的数据,然后按 ENTER,然后按2"、ENTER、3"等.但在 XML 中,因此在 PDF 中,输出是1234567".如何保留换行符?我已经尝试过 white-space-collapselinefeed-treatmentwhite-space-treatment 但这没有帮助.

I am generating a PDF using XSL-FO and XML. In a textbox, the user can enter data like "1", then he presses ENTER, then "2", ENTER, "3", etc. But in the XML and hence in the PDF, the output is "1234567". How can I preserve the line breaks? I already tried white-space-collapse, linefeed-treatment and white-space-treatment but that didn't help.

我的 XSL 看起来像:

My XSL looks like:

<xsl:template match="AddCmt">
    <fo:block keep-together="always"> Additional Comments 
        <fo:block-container border-style="solid" height="20mm" width="170mm" space-after="5mm"> 
            <fo:block> 
                <xsl:attribute name="id"> 
                    <xsl:value-of select="../CMT_ID"/> 
                </xsl:attribute> 
                <xsl:value-of select="../ANS_CMT"/> 
            </fo:block> 
        </fo:block-container> 
    </fo:block> 
</xsl:template> 

当我输入以下内容时:

hello
medhavi
saraswat

这是我得到的 XML:

This is the XML I get:

<?xml version="1.0" encoding="UTF-8" ?> 
<?xml-stylesheet type='text/xsl' href='e:\tmm-09.3\src\pmod\WorkOrder.xsl'?>
    <Root>
        <WorkOrders>
            <Detail>Id="ANS_436‌​_FLD_1" Label="qq">qq</Detail>
            <Ans Checked="0" Id="ANS_436_FLD_2" Label="ww">ww</Ans>
            <ID>ANS_436_FLD</ID>
            <ANS_FLD>0|0</ANS_FLD>
            <CMT_ID>ANS_436_CMT‌​</CMT_ID>
            <ANS_CMT>hello medhavi saraswat</ANS_CMT>
            <Warning>
                <Line>warning 11</Line>
                <Line>22</Line>
                <Line>33</Line>
                <Line>44</Line>
                <Line></Line>
                <Line>66</Lin‌​e>
                <Line>77</Line>
                <Line></Line>
            </Warning>

推荐答案

它应该适用于以下 xml(您应该添加所有属性):

It should work with the following xml (you should add all the attributes):

<xsl:template match="AddCmt">
    <fo:block keep-together="always"> Additional Comments 
        <fo:block-container border-style="solid" height="20mm" width="170mm" space-after="5mm"> 
            <fo:block wrap-option="wrap" linefeed-treatment="preserve" white-space-collapse="false" white-space-treatment="preserve"> 
                <xsl:attribute name="id"> 
                    <xsl:value-of select="../CMT_ID"/> 
                </xsl:attribute> 
                <xsl:value-of select="../ANS_CMT"/> 
            </fo:block> 
        </fo:block-container> 
    </fo:block> 
</xsl:template> 

但正如我在评论中提到的,如果您的 XML 已经没有换行符,那么您的 PDF 就不可能.您在问题中提到 XML 中没有换行符,因此 PDF 中没有换行符.

But as I mentioned in the comments, if your XML already has no linebreaks, there's no way your PDF will. You mentioned in your question there are no linebreaks in your XML, hence no linebreaks in the PDF.

尝试检查为什么 XML 中没有换行符.如果您可以提供更多信息(您的 XML 的一部分、您用于构造 XML 的代码等),请编辑您的答案并添加信息.

Try checking out why there are no linebreaks in the XML. If you can provide any more information (a piece of your XML, the code you use to construct the XML, ...), please edit your answer and add the information.

这篇关于如何在用 XSL-FO 生成的 PDF 中插入换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆