Inserting a line break in a PDF generated from XSL FO using

后端 未结 11 748
挽巷
挽巷 2020-12-03 17:16

I am using XSL FO to generate a PDF file containing a table with information. One of these columns is a \"Description\" column. An example of a string that I am populating o

相关标签:
11条回答
  • 2020-12-03 17:21

    You shouldn't use xsl:value-of instruction but xsl:apply-templates instead: for built-in rule for text node will just output their string value, and for empty br element you could declare a rule matching descriptionStr/br or descriptionStr//br (depending your input) in order to transform to empty fo:block.

    0 讨论(0)
  • 2020-12-03 17:22

    This helped me and should be simplest solution (working with Apache FOP 1.1):

    Why not replace your <br/> with Unicode character called line separator.

       <xsl:template match="br">
          <xsl:value-of select="'&#x2028;'"/>
       </xsl:template>
    

    See https://en.wikipedia.org/wiki/Newline#Unicode

    0 讨论(0)
  • 2020-12-03 17:22

    Try this:

    <fo:block><fo:inline color="transparent">x</fo:inline></fo:block>

    This code adds a block which contains transparent text, making it look like a new line.

    0 讨论(0)
  • 2020-12-03 17:25

    </fo:block> on it's own is not a direct substitute for <br/> <br/> is an html unpaired abberation that has no direct equivalent in xsl:fo

    </fo:block> just means end of block. If you scatter them through your text you wont have valid xml, and your xsl processor will sick up errors.

    For the line break formatting you want, each block will occur on a new line. You need a <fo:block> start block and </fo:block> end block pair for each line.

    0 讨论(0)
  • 2020-12-03 17:32

    I usually use an empty block with a height that can be changed if I need more or less space:

    <fo:block padding-top="5mm" />
    

    I know this isn't the best looking solution but it's funtional.

    0 讨论(0)
  • 2020-12-03 17:33

    The following code worked:

    <fo:block white-space-collapse="false" 
        white-space-treatment="preserve" 
        font-size="0pt" line-height="15px">.</fo:block>
    

    It makes the xsl processor thinks this block contains a line of text, which actually has a 0pt font size. You can customize line height by providing your own value.

    0 讨论(0)
提交回复
热议问题