I am trying to work with xsl:fo to create pdf. I am stuck on problem with inline elements. I need to write line with one bold word. For example:
I need this to be bold.
I could do that with this code:
<fo:block>
<fo:inline>I need </fo:inline><fo:inline font-weight="bold">this</fo:inline><fo:inline> to be bold</fo:inline>
</fo:block>
But since I write the xml programmaticaly, it will be pretty printed (i could disable it, but then it would be on one line and that is not human readable.
It does not work when formatted like this:
<fo:block>
<fo:inline>I need </fo:inline>
<fo:inline font-weight="bold">this</fo:inline>
<fo:inline> to be bold</fo:inline>
</fo:block>
It makes large horizontal spaces between the texts when pdf is generated.
Do you have any idea how to make this work? Thanks a lot.
I agree with @Andremonly.
Check that you are not setting white-space-collapse="false"
(see https://www.w3.org/TR/xsl11/#white-space-collapse) on any ancestor FO.
There are additional properties that affect white-space handling. Which of these matches what you see?
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="page"
margin="0.1in" page-height="4in" page-width="3in">
<fo:region-body region-name="body" margin="6pt"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="page">
<fo:flow flow-name="body">
<fo:block>
<fo:inline>I need </fo:inline>
<fo:inline font-weight="bold">this</fo:inline>
<fo:inline> to be bold</fo:inline>
</fo:block>
<fo:block white-space-collapse="false">
<fo:inline>I need </fo:inline>
<fo:inline font-weight="bold">this</fo:inline>
<fo:inline> to be bold</fo:inline>
</fo:block>
<fo:block white-space-treatment="preserve">
<fo:inline>I need </fo:inline>
<fo:inline font-weight="bold">this</fo:inline>
<fo:inline> to be bold</fo:inline>
</fo:block>
<fo:block white-space-treatment="preserve" white-space-collapse="false">
<fo:inline>I need </fo:inline>
<fo:inline font-weight="bold">this</fo:inline>
<fo:inline> to be bold</fo:inline>
</fo:block>
<fo:block linefeed-treatment="preserve">
<fo:inline>I need </fo:inline>
<fo:inline font-weight="bold">this</fo:inline>
<fo:inline> to be bold</fo:inline>
</fo:block>
<fo:block white-space-collapse="false" linefeed-treatment="preserve">
<fo:inline>I need </fo:inline>
<fo:inline font-weight="bold">this</fo:inline>
<fo:inline> to be bold</fo:inline>
</fo:block>
<fo:block white-space-treatment="preserve" linefeed-treatment="preserve">
<fo:inline>I need </fo:inline>
<fo:inline font-weight="bold">this</fo:inline>
<fo:inline> to be bold</fo:inline>
</fo:block>
<fo:block white-space-treatment="preserve" white-space-collapse="false" linefeed-treatment="preserve">
<fo:inline>I need </fo:inline>
<fo:inline font-weight="bold">this</fo:inline>
<fo:inline> to be bold</fo:inline>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>