Discussion:
Page breaks and absolute positioned block-containers
Lien, Patrick
2004-03-08 03:31:39 UTC
Permalink
I have 2 .fo files that I'm trying to integrate into a single XSL-FO
template that I hope to use to generate a 2-page PDF file. Each .fo file
uses all absolutely positioned block containers. They are, in fact, the
output from an FO editor (XSLFast).

I tried merging the .fo files and placing a break-before="page" in the 1st
block-container element that came from the second .fo file. Since all the
block-containers are absolutely positioned, this element is not necessarily
the first element that would normally be encountered in the flow.

However, the page break does not work, and I end up with a 1 page PDF with
the contents of both pages overlaid on top of each other.

I've also tried:
* Using break-after="page"
* Nesting the entire contents of the 1st and second pages in a
block-container element, but that did not work either.

How can I get a 2-page PDF from my .fo files?

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE xml [<!ENTITY copy "&#169;"> <!ENTITY trade "&#8482;"> <!ENTITY
deg "&#x00b0;"> <!ENTITY gt "&#62;"> <!ENTITY sup2 "&#x00b2;"> <!ENTITY
frac14 "&#x00bc;"> <!ENTITY quot "&#34;"> <!ENTITY frac12 "&#x00bd;">
<!ENTITY euro "&#x20ac;"> <!ENTITY Omega "&#937;"> ]> <!-- Document
generated with XSLfast v1.3 -->

<xsl:stylesheet xmlns:fox="http://xml.apache.org/fop/extensions"
xmlns:print="http://www.jcatalog.com/com.jcatalog.output.xslextensions.print
.PrintElementFactory" xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:saxon="http://icl.com/saxon" extension-element-prefixes="saxon print"
<xsl:variable name="currentDate" >01-03-2004 10:47:11</xsl:variable>
<xsl:variable name="IMAGEEXT">gif</xsl:variable>
<xsl:template match="xml">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="pagemaster1"
page-height="792.0pt" page-width="612.0pt">
<fo:region-body margin-left="20pt" margin-top="8pt"
margin-bottom="8pt" margin-right="18pt"/>
<fo:region-before extent="8pt"/>
<fo:region-after extent="8pt" />
<fo:region-start extent="20pt" />
<fo:region-end extent="18pt" />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="pagemaster1">
<fo:static-content flow-name="xsl-region-before" >
</fo:static-content>
<fo:static-content flow-name="xsl-region-after" >
</fo:static-content>
<fo:static-content flow-name="xsl-region-start" >
</fo:static-content>
<fo:static-content flow-name="xsl-region-end" >
</fo:static-content>

<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates/>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>


<xsl:template match="alphafactbookupdate">
<!-- *** Page 1 content *** -->
<fo:block-container position="absolute" top="183pt" left="390pt"
height="343.0pt" width="23.0pt" >
<fo:block>
<fo:instream-foreign-object>
<svg:svg xmlns:svg="http://www.w3.org/2000/svg" width = "8.0"
height="328.0">
<svg:g style="stroke:#b3b9c9; stroke-width:1.0">
<svg:line x1="2.0pt" y1="2.0pt" x2="2.0pt" y2="322.0pt" />
</svg:g>
</svg:svg>
</fo:instream-foreign-object>
</fo:block>
</fo:block-container>
<!-- OFFSET = 1.0 -->
<fo:block-container position="absolute" top="183pt" left="569pt"
height="343.0pt" width="23.0pt" >
<fo:block>
.
.
.

<fo:block-container position="absolute" top="578pt" left="5pt"
height="25.0pt" width="565.0pt" >
<fo:block >
<xsl:variable
name="filename">../../fundimages/head_top_ten_long.gif</xsl:variable>
<fo:external-graphic src="{$filename}" position="relative"
top="586pt" left="25pt"/>
</fo:block>
</fo:block-container>
<!-- ********** PAGE 2 ************* -->
<fo:block-container break-before="page" position="absolute" top="1pt"
left="392pt" height="225.0pt" width="180.0pt" >
<fo:block >
<xsl:variable name="filename"><xsl:value-of
select="fundimages/stylebox/styleboxdata"/></xsl:variable>
<fo:external-graphic src="{$filename}" position="relative" top="9pt"
left="410pt"/>
</fo:block>
.
.
.
</fo:block-container>
<!-- ********** END PAGE 2 ********* -->
</xsl:template>

</xsl:stylesheet>
Chris Bowditch
2004-03-08 09:32:27 UTC
Permalink
Lien, Patrick wrote:

<snip/>
Post by Lien, Patrick
* Using break-after="page"
* Nesting the entire contents of the 1st and second pages in a
block-container element, but that did not work either.
How can I get a 2-page PDF from my .fo files?
try creating two simple page masters, with different named header
regions. Then put all the block containers into static content, those
for page 1 going into header 1, those for page 2 going into header 2.
They are absolutely positioned and wont be confined to the static
content area. In the flow place a single empty block with a
break-after="page" to ensure the second page is activated.

Chris
Lien, Patrick
2004-03-08 17:16:33 UTC
Permalink
Thanks, Chris. That did the trick.

However, since all the absolute positions of the block containers were
relative to the body region with the start and before regions set to
non-zero extents, I ended up putting all the containers/static content into
the end region, and expanding the extent of the end region to take up all
the space from the right edge of the page back to the right side of the
before region:

<fo:layout-master-set>
<fo:simple-page-master master-name="page1" page-height="792.0pt"
page-width="612.0pt">
<fo:region-body />
<fo:region-before extent="8pt" precedence="true"/>
<fo:region-after extent="8pt" />
<fo:region-start extent="20pt" />
<fo:region-end region-name="page1content" extent="592pt" />
</fo:simple-page-master>
<fo:simple-page-master master-name="page2" page-height="792.0pt"
page-width="612.0pt">
<fo:region-body />
<fo:region-before extent="8pt" precedence="true"/>
<fo:region-after extent="8pt" />
<fo:region-start extent="20pt" />
<fo:region-end region-name="page2content" extent="592pt" />
</fo:simple-page-master>
<fo:page-sequence-master master-name="factsheetsequence">
<fo:single-page-master-reference master-reference="page1"/>
<fo:single-page-master-reference master-reference="page2"/>
</fo:page-sequence-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="factsheetsequence">
<fo:static-content flow-name="page1content" >
<!-- *** Begin Page 1 content FO *** -->
<fo:block-container position="absolute" top="183pt"
left="390pt" height="343.0pt" width="23.0pt" >
.
.
.
</fo:static-content>
<!-- *** End Page 1 content FO *** -->
<fo:static-content flow-name="page2content" >
<!-- *** Begin Page 2 content FO *** -->
<fo:block-container position="absolute" top="1pt"
left="392pt" height="225.0pt" width="180.0pt" >
.
.
.
</fo:block-container>
<!-- *** End Page 2 content FO *** -->
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:block break-after="page"/>
</fo:flow>
</fo:page-sequence>

Loading...