Keeping together a text line with the first row in a table

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Keeping together a text line with the first row in a table

Lars Bjørndal-2
I use a Perl script to generate a fo file out of a non-standard csv
format. The structure is one line of text, and then a table with several
rows, then one line of text, and a new table and so on. The single lines
of text is actually a heading, and should not go to the bottom line of a
page. Instead, it should go to a new page.

To generate the PDF output, I use fop version 0.95 on a Fedora Linux
system.

The fo file structure looks like the following:

<?xml version="1.0" encoding="ISO-8859-1"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
  font-family="Helvetica" font-size="18pt">
   <fo:layout-master-set>
     <fo:simple-page-master master-name="A4-landscape"
      reference-orientation="90" page-width="21cm"
      page-height="29.7cm"
      margin-left="2cm" margin-right="1cm" margin-top=".5cm" margin-bottom="2cm">
      <fo:region-body margin-top=".5cm"/>
      <fo:region-before extent="0cm"/>
      <fo:region-after extent=".5cm"/>
    </fo:simple-page-master>
  </fo:layout-master-set>

  <fo:page-sequence master-reference="A4-landscape">
    <fo:static-content flow-name="xsl-region-after">
      <fo:block text-align-last="right" font-size="10pt">
        <fo:page-number />
      </fo:block>
    </fo:static-content>
    <fo:flow flow-name="xsl-region-body">
      <fo:block font-weight="bold">The first hading</fo:block>

      <fo:table table-layout="fixed" width="100%" border-width=".5mm" border-style="dotted">
        <fo:table-column column-width="2cm" />
        <fo:table-column column-width="10cm" />
        <fo:table-column column-width="8cm" />
        <fo:table-column column-width="5cm" />
        <fo:table-body>

        <fo:table-row>
          <fo:table-cell padding=".5mm" border-width=".5mm"
              border-style="dotted" text-align="center">
            <fo:block>1</fo:block>
          </fo:table-cell>
          <fo:table-cell padding=".5mm" border-width=".5mm" border-style="dotted">
            <fo:block>John Johnsen</fo:block>
          </fo:table-cell>
          <fo:table-cell padding=".5mm" border-width=".5mm" border-style="dotted">
            <fo:block>NOR-Oslo</fo:block>
          </fo:table-cell>
                    <fo:table-cell padding=".5mm" border-width=".5mm"
                    border-style="dotted" text-align="right">
                      <fo:block>30.40</fo:block>
                    </fo:table-cell>
        </fo:table-row>

        <fo:table-row>
          <fo:table-cell padding=".5mm" border-width=".5mm"
              border-style="dotted" text-align="center">
            <fo:block>2</fo:block>
          </fo:table-cell>
          <fo:table-cell padding=".5mm" border-width=".5mm" border-style="dotted">
            <fo:block>Jack Jacksen</fo:block>
          </fo:table-cell>
          <fo:table-cell padding=".5mm" border-width=".5mm" border-style="dotted">
            <fo:block>NOR-Oslo</fo:block>
          </fo:table-cell>
                    <fo:table-cell padding=".5mm" border-width=".5mm"
                    border-style="dotted" text-align="right">
                      <fo:block>39.30</fo:block>
                    </fo:table-cell>
        </fo:table-row>
        </fo:table-body>
      </fo:table>

      <fo:block font-weight="bold">The second heading</fo:block>

And then, a new table. ...

How can I keep together the heading with the first row in the table?

Regards,
Lars


Reply | Threaded
Open this post in threaded view
|

Re: Keeping together a text line with the first row in a table

G. Ken Holman
At 2011-04-13 14:18 +0200, Lars Bjørndal wrote:
>The structure is one line of text, and then a table with several
>rows, then one line of text, and a new table and so on. The single lines
>of text is actually a heading, and should not go to the bottom line of a
>page. Instead, it should go to a new page.

To force it to a new page, use break-before="page" on the heading.

>...
>How can I keep together the heading with the first row in the table?

To keep the heading together with the table, but
not force a new page unless necessary, use
keep-with-next="always" on the heading.  If both
the heading and the start of the table fit on the
page, they will go on the page without a page
break.  If the two do not fit on the page, then
the formatter should introduce a page-break.

There are some subtleties you might need.  For
example, if you have multi-column pages and you
only want to introduce a column-break instead of
a page-break, then use keep-with-next.within-column="always".

The value "always" can be replaced with a number
when you are nesting keeps, but I doubt that FOP
supports the numeric values and associated
complexity.  I don't use FOP but I'm assuming it
at the least supports "always".

I hope this helps.

. . . . . . . . . . . Ken

--
Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/f/
G. Ken Holman                 mailto:[hidden email]
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


Reply | Threaded
Open this post in threaded view
|

Re: Keeping together a text line with the first row in a table

Jeremias Maerki-2
Apache FOP does the following:

- always: never allow a break (save for break-before|after which is
stronger). Overflows can happen as a result.
- any integer: allow a break if otherwise the section overflows. No
distinction between the integer values, i.e. 1=3.

On 13.04.2011 16:40:35 G. Ken Holman wrote:
<snip/>
> The value "always" can be replaced with a number
> when you are nesting keeps, but I doubt that FOP
> supports the numeric values and associated
> complexity.  I don't use FOP but I'm assuming it
> at the least supports "always".
<snip/>


Jeremias Maerki