Search code examples
pdfxsltxsl-foapache-fop

XSL FO inline-container remove margins and align next to each other


First of all: i use Apache Formatting Objects Processor 2.3 for generating PDF files

There are two questions that build on each other, so I wanted to put them together in one post.

I have a .fo file in which i created labeled text blocks where a title is in a left bounded block and the content text in a right bounded block.

First i implemented that with fo:table elements, but for reasons that are not important here, i need to go with fo:inline-container instead.

So this is a simplified .fo file of mine:

<?xml version="1.0" encoding="UTF-8"?>
<fo:root
    xmlns="http://www.w3.org/1999/XSL/Format"
    xmlns:fo="http://www.w3.org/1999/XSL/Format">

    <fo:layout-master-set>
        <fo:simple-page-master master-name="Inhalt-Seiten" page-height="29.7cm" page-width="21cm" margin-top="1.5cm" margin-bottom="1.5cm" margin-left="2cm" margin-right="1.5cm">
            <fo:region-body margin-top="3.5cm" margin-bottom="1.25cm" margin-left="1cm" margin-right="1cm"/>
            <fo:region-before region-name="MAIN-EVEN-header" extent="3.5cm"/>
            <fo:region-after extent="1.25cm"/>
            <fo:region-start region-name="MAIN-EVEN-left" extent="1cm"/>
            <fo:region-end extent="1cm"/>
        </fo:simple-page-master>
    </fo:layout-master-set>
    <fo:page-sequence master-reference="Inhalt-Seiten">
        <fo:flow flow-name="xsl-region-body">
            <fo:block background-color="green">
                <fo:inline-container inline-progression-dimension="20%" vertical-align="top" background-color="yellow">
                    <fo:block>
                        Test
                    </fo:block>
                </fo:inline-container>
                <fo:inline-container inline-progression-dimension="80%" vertical-align="top" background-color="red">
                    <fo:block>
                        Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
                    </fo:block>
                </fo:inline-container>
            </fo:block>
        </fo:flow>
    </fo:page-sequence>
</fo:root>

That creates the following output:

PDFOutput

Question 1 - Alignment

So first of all: why are they not aligned next to each other? I could set the yellow `inline-progression-dimension` to `19%` and the red `inline-progression-dimension` to `79%` but this leads to gaps that I do not want (see picture).

newpercentages

Question 2 - Top and bottom margins

As you can see, the green block sticks out a little at the top and bottom. Is there any way to prevent this? I have now already tried to set the margins and paddings to 0 but without success

Solution

  • Solved by using a fo:list-block instead of fo:inline-container.

    Thanks to @Tony Graham

    <fo:block background-color="green">
        <fo:list-block provisional-label-separation="0pt" provisional-distance-between-starts="20%">
            <fo:list-item>
                <fo:list-item-label end-indent="label-end()">
                    <fo:block background-color="yellow">
                        Test
                    </fo:block>
                </fo:list-item-label>
                <fo:list-item-body start-indent="body-start()">
                    <fo:block background-color="red">
                        Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
                    </fo:block>
                </fo:list-item-body>
            </fo:list-item>
        </fo:list-block>
    </fo:block>
    

    Creates the desired output with no margins and perfectly aligned:

    output