• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XSL Page break

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I use fop in my application to convert html-to-pdf. Apart from using the jar, there is an html-to-pdf.xsl that helps this process.

I am having problems in page breaks in that the page that is generated after the break has a big white space before the contents actually begin. This is causing an issue as the first page is not consistent with the rest.

This was found on the internet by my colleague and we have coded none of it.

I am copy-pasting the specific code that (I think!) helps in page breaks.

Please let me know how the space-after-page-break can be avioded. Any help would be much appreciated. Thanks in advance.


<!-- ============================================
We render the <h1> by putting a horizontal rule
and a page break before it. We also process
the id attribute; if the <h1> tag has one, we
use it. If not, we see if the preceding element
is a named anchor (<a name="x"/> . If there is
a named anchor before the <h1>, we use the name
of the anchor point as the id.
=============================================== -->

<xsl:template match="h1">
<fo:block break-before="page"></fo:block>
<fo:block font-size="28pt" line-height="32pt"
keep-with-next="always"
space-after="22pt" font-family="serif">
<xsl:attribute name="id">
<xsl:choose>
<xsl:when test="@id">
<xsl:value-of select="@id"/>
</xsl:when>
<xsl:when test="name(preceding-sibling::*[1]) = 'a' and
preceding-sibling::*[1][@name]">
<xsl:value-of select="preceding-sibling::*[1]/@name"/>
</xsl:when>
<xsl therwise>
<xsl:value-of select="generate-id()"/>
</xsl therwise>
</xsl:choose>
</xsl:attribute>
<xsl:apply-templates select="*|text()"/>
</fo:block>
</xsl:template>
 
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It has been awhile since I mucked with this stuff, but I seem to recall there was an option you could specify in XSLT that controlled how whitespace was to be handled. If you didn't use that option and were outputting XML you generally didn't notice the difference one way or another because you only care about structure, but in other circumstances you found that the XSL processor was picking up assorted bits of whitespace from the input document and the stylesheet and dumping them where you didn't expect it unless you traced the execution carefully enough to really explain it. I'd look at the W3C XSLT spec for more info.
reply
    Bookmark Topic Watch Topic
  • New Topic