conditional page break

View: New views
10 Messages — Rating Filter:   Alert me  

conditional page break

by Tamsin-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hi,

 

I am trying to find a way to conditionally start a new page within a PDF. Basically, if block A fits on one page, even with space remaining, block B should start on a new page. But if block A runs onto the next page, block B should start straight after block A.

 

I can’t see a way to do this – I first looked into comparing the page numbers, but obviously you can’t do this at the XSL step of the process. Wondered if anyone can suggest a solution?

 

Thanks,

Tamsin

 

 


Re: conditional page break

by John Virgo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've had the same problem in a long running project (2 years) that I am still working.

I call this problem 'layout feedback', or lack of. The problem is there is no accurate way of determining if 'block A fits' into any area until the FO has been laid out so your XSL will not be able to make the decision.

I've worked around this in several ways, none of which are pretty:
* Run a template for just block A and check the page count output, to make the decision of which template to use.
* Manually calculate the size of block A using the font size and known quantities of the layout directly in the FO.
* As above but with custom pre-parsing code on the input XML passing a parameter to the XSL template.

I'm sure there were more I tried but nothing worked particularly well, in the end we hand to settle for allow our QA users to make the decision using a tick box on the form displaying (and regenerating) the output.

JV


Tamsin-3 wrote:
Hi,

 

I am trying to find a way to conditionally start a new page within a PDF.
Basically, if block A fits on one page, even with space remaining, block B
should start on a new page. But if block A runs onto the next page, block B
should start straight after block A.

 

I can't see a way to do this - I first looked into comparing the page
numbers, but obviously you can't do this at the XSL step of the process.
Wondered if anyone can suggest a solution?

 

Thanks,

Tamsin

 

 

Re: conditional page break

by Jeremias Maerki-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It's a bit difficult from your description how exactly the rules should
be but you should look at the "keep-together.within-column" property.
That allows you to keep blocks together and (using integer values) even
define relative strengths that allow a formatter to keep blocks together
or still break them if absolutely necessary. I assume you were
experimenting with break-before/break-after but that can only be used
for hard breaks. Coming from the other direction (keeps) might be your
solution. HTH

http://www.w3.org/TR/xsl11/#keepbreak
http://www.w3.org/TR/xsl11/#keep-together

On 20.10.2009 16:55:49 Tamsin wrote:

> Hi,
>  
> I am trying to find a way to conditionally start a new page within a PDF.
> Basically, if block A fits on one page, even with space remaining, block B
> should start on a new page. But if block A runs onto the next page, block B
> should start straight after block A.
>  
> I can't see a way to do this - I first looked into comparing the page
> numbers, but obviously you can't do this at the XSL step of the process.
> Wondered if anyone can suggest a solution?
>  
> Thanks,
> Tamsin




Best regards,
Jeremias Märki
_________________________________________________________
Jeremias Märki, Software-Development and Consulting
Contact Information: http://www.jeremias-maerki.ch/contact.html
Blog: http://www.jeremias-maerki.ch/blog/



RE: conditional page break

by Tamsin-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Thanks very much for this - it confirms what I was thinking. Hadn't thought
of the workaround of running just block A first and getting a page count, so
may try that. My document has a lot of sections all with block A's though so
could see this slowing the process down a lot.

Thanks again,
Tamsin


-----Original Message-----
From: www-xsl-fo-request@... [mailto:www-xsl-fo-request@...] On Behalf
Of John Virgo
Sent: 22 October 2009 09:06
To: www-xsl-fo@...
Subject: Re: conditional page break


I've had the same problem in a long running project (2 years) that I am
still
working.

I call this problem 'layout feedback', or lack of. The problem is there is
no accurate way of determining if 'block A fits' into any area until the FO
has been laid out so your XSL will not be able to make the decision.

I've worked around this in several ways, none of which are pretty:
* Run a template for just block A and check the page count output, to make
the decision of which template to use.
* Manually calculate the size of block A using the font size and known
quantities of the layout directly in the FO.
* As above but with custom pre-parsing code on the input XML passing a
parameter to the XSL template.

I'm sure there were more I tried but nothing worked particularly well, in
the end we hand to settle for allow our QA users to make the decision using
a tick box on the form displaying (and regenerating) the output.

JV



Tamsin-3 wrote:

>
> Hi,
>
>  
>
> I am trying to find a way to conditionally start a new page within a PDF.
> Basically, if block A fits on one page, even with space remaining, block B
> should start on a new page. But if block A runs onto the next page, block
> B
> should start straight after block A.
>
>  
>
> I can't see a way to do this - I first looked into comparing the page
> numbers, but obviously you can't do this at the XSL step of the process.
> Wondered if anyone can suggest a solution?
>
>  
>
> Thanks,
>
> Tamsin
>
>  
>
>  
>
>
>

--
View this message in context:
http://www.nabble.com/conditional-page-break-tp25979086p26005680.html
Sent from the w3.org - www-xsl-fo mailing list archive at Nabble.com.





RE: conditional page break

by Tamsin-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Thanks for this - I have tried various keep together options, but it doesn’t
solve the problem. Its not a case of only splitting the blocks when
absolutely necessary - I want to specifically start a new page, IF the first
block is less than a page long.

Its sounding like it can't be done, but I appreciate the suggestions.

Thanks,
Tamsin


-----Original Message-----
From: www-xsl-fo-request@... [mailto:www-xsl-fo-request@...] On Behalf
Of Jeremias Maerki
Sent: 22 October 2009 09:10
To: www-xsl-fo@...
Subject: Re: conditional page break

It's a bit difficult from your description how exactly the rules should
be but you should look at the "keep-together.within-column" property.
That allows you to keep blocks together and (using integer values) even
define relative strengths that allow a formatter to keep blocks together
or still break them if absolutely necessary. I assume you were
experimenting with break-before/break-after but that can only be used
for hard breaks. Coming from the other direction (keeps) might be your
solution. HTH

http://www.w3.org/TR/xsl11/#keepbreak
http://www.w3.org/TR/xsl11/#keep-together

On 20.10.2009 16:55:49 Tamsin wrote:
> Hi,
>  
> I am trying to find a way to conditionally start a new page within a PDF.
> Basically, if block A fits on one page, even with space remaining, block B
> should start on a new page. But if block A runs onto the next page, block
B
> should start straight after block A.
>  
> I can't see a way to do this - I first looked into comparing the page
> numbers, but obviously you can't do this at the XSL step of the process.
> Wondered if anyone can suggest a solution?
>  
> Thanks,
> Tamsin




Best regards,
Jeremias Märki
_________________________________________________________
Jeremias Märki, Software-Development and Consulting
Contact Information: http://www.jeremias-maerki.ch/contact.html
Blog: http://www.jeremias-maerki.ch/blog/





Re: conditional page break

by Tony Graham-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Oct 20 2009 15:55:49 +0100, tamsin@... wrote:
> I am trying to find a way to conditionally start a new page within a PDF.
> Basically, if block A fits on one page, even with space remaining, block B
> should start on a new page. But if block A runs onto the next page, block B
> should start straight after block A.

If you are using an XSL 1.1 processor and A is the only thing on its
page, then you could use a flow map and put A and B in separate flows.

You could direct A to its page and the second page, and direct B to the
second page.  If A overflows its page, its flow would continue on the
second page.

The fo:layout-master-set would have to have just a
fo:single-page-master-reference for the first page.

Regards,


Tony Graham                         Tony.Graham@...
Director                                  W3C XSL FO SG Invited Expert
Menteith Consulting Ltd                               XML Guild member
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599   http://www.menteithconsulting.com
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
xmlroff XSL Formatter                               http://xmlroff.org
xslide Emacs mode                  http://www.menteith.com/wiki/xslide
Unicode: A Primer                               urn:isbn:0-7645-4625-2


Re: conditional page break

by John Virgo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Could you provide a little more detail around the flow-map?

Tony Graham-3 wrote:
On Tue, Oct 20 2009 15:55:49 +0100, tamsin@anorakgirl.co.uk wrote:
> I am trying to find a way to conditionally start a new page within a PDF.
> Basically, if block A fits on one page, even with space remaining, block B
> should start on a new page. But if block A runs onto the next page, block B
> should start straight after block A.

If you are using an XSL 1.1 processor and A is the only thing on its
page, then you could use a flow map and put A and B in separate flows.

You could direct A to its page and the second page, and direct B to the
second page.  If A overflows its page, its flow would continue on the
second page.

The fo:layout-master-set would have to have just a
fo:single-page-master-reference for the first page.

Regards,


Tony Graham                         Tony.Graham@MenteithConsulting.com
Director                                  W3C XSL FO SG Invited Expert
Menteith Consulting Ltd                               XML Guild member
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599   http://www.menteithconsulting.com
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
xmlroff XSL Formatter                               http://xmlroff.org
xslide Emacs mode                  http://www.menteith.com/wiki/xslide
Unicode: A Primer                               urn:isbn:0-7645-4625-2

Re: conditional page break

by Tony Graham-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Oct 22 2009 15:07:13 +0100, John.Virgo@... wrote:
> Could you provide a little more detail around the flow-map?

The flow map directs flows to regions.

In XSL 1.1, you can have more than one fo:region-body within a
fo:simple-page-master, and each xsl:region-body has to have a different
"region-name" and may have different positions on the page.

See http://www.w3.org/TR/xsl11/#d0e7194 for flow-map examples.

Unfortunately, I couldn't solve Tamsin's problem using flow-maps after
all: the best that I could do on the second page was to put A and B in
different regions, so it couldn't look like B directly followed A when A
overflowed onto the second page.

However, if A is always going to be large enough, and B is never going
to be small enough, that all of A and all of B can fit on one page, then
you can put B in a fo:block-container, specify a mimimum
block-progression-dimension, and set overflow to "repeat".  If the
minimum is larger than the maximum BPD that A will leave on the first
page, then B will always start on the second page, but if B overflows
that page, it will just generate more areas on the third page.  The
issue then becomes whether A will always leave enough room on the second
page for B's minimum BPD, otherwise B would start on the third page
instead of on the second page after the end of the large A.

------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xlink="http://www.w3.org/1999/xlink">
  <fo:layout-master-set>
    <fo:simple-page-master page-height="297mm" page-width="210mm" margin-right="0.75in" margin-left="0.2in" margin-bottom="0.0in" margin-top="0.375in" master-name="a">
      <fo:region-body margin-bottom="0.9in" margin-top="0.6in" region-name="xsl-region-body"/>
    </fo:simple-page-master>
    <fo:page-sequence-master master-name="master">
      <fo:repeatable-page-master-reference  master-reference="a"/>
    </fo:page-sequence-master>
  </fo:layout-master-set>
    <fo:page-sequence master-reference="master">
      <fo:flow flow-name="xsl-region-body" font-size="72pt">
        <fo:block>A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A</fo:block>
        <fo:block-container overflow="repeat" block-progression-dimension.minimum="200mm"><fo:block>B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B</fo:block></fo:block-container>
      </fo:flow>
    </fo:page-sequence>
    <fo:page-sequence master-reference="master">
      <fo:flow flow-name="xsl-region-body" font-size="72pt">
        <fo:block>A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A</fo:block>
        <fo:block-container overflow="repeat" block-progression-dimension.minimum="200mm"><fo:block>B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B</fo:block></fo:block-container>
      </fo:flow>
    </fo:page-sequence>
</fo:root>
------------------------------------------------------------

Regards,


Tony Graham                         Tony.Graham@...
Director                                  W3C XSL FO SG Invited Expert
Menteith Consulting Ltd                               XML Guild member
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599   http://www.menteithconsulting.com
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
xmlroff XSL Formatter                               http://xmlroff.org
xslide Emacs mode                  http://www.menteith.com/wiki/xslide
Unicode: A Primer                               urn:isbn:0-7645-4625-2


Re: conditional page break

by Tony Graham-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Oct 22 2009 09:06:11 +0100, John.Virgo@... wrote:
> I've had the same problem in a long running project (2 years) that I am still
> working.
>
> I call this problem 'layout feedback', or lack of. The problem is there is
> no accurate way of determining if 'block A fits' into any area until the FO
> has been laid out so your XSL will not be able to make the decision.

To unofficially wear my other hat for a moment, please consider
reviewing the XSL 2.0 Requirements at http://www.w3.org/TR/xslfo20-req/
to see whether they cover your problem.  You may particularly want to
look at Section 2.3, "Feedback from pagination stage", and Section 3.1,
"Including information from formatting time".

The Requirements document encourages providing comments and feedback on
individual requirements using the W3C Bugzilla system at
http://www.w3.org/Bugs/Public/.  See the instructions at
http://www.w3.org/XML/2008/01/xsl-fo-bugzilla.html#comment

Regards,


Tony Graham                         Tony.Graham@...
Director                                  W3C XSL FO SG Invited Expert
Menteith Consulting Ltd                               XML Guild member
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599   http://www.menteithconsulting.com
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
xmlroff XSL Formatter                               http://xmlroff.org
xslide Emacs mode                  http://www.menteith.com/wiki/xslide
Unicode: A Primer                               urn:isbn:0-7645-4625-2


RE: conditional page break

by Tamsin-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Thanks for the suggestion, I will experiment with this, as the idea would
certainly solve the problem (Basically don't start the second section on the
same page if you're really near the bottom).
I think the problem will be that I have oversimplified the situation. My
region body has two columns, and what I have been calling 'block B' is
actually a short block header which spans both columns, followed by a long
block which does not span columns (hence my other post about getting the
spanning block to stick with the non-spanning block). I don't think I can
put both in a block-container without losing the span/don't span ability -
May have to get customer to agree to some simplifications!

Thanks for looking into this, and I will be sure to review the XSL 2.0
requirements.

Tamsin

-----Original Message-----
From: www-xsl-fo-request@... [mailto:www-xsl-fo-request@...] On Behalf
Of Tony Graham
Sent: 22 October 2009 22:34
To: www-xsl-fo@...
Subject: Re: conditional page break

On Thu, Oct 22 2009 15:07:13 +0100, John.Virgo@... wrote:
> Could you provide a little more detail around the flow-map?

The flow map directs flows to regions.

In XSL 1.1, you can have more than one fo:region-body within a
fo:simple-page-master, and each xsl:region-body has to have a different
"region-name" and may have different positions on the page.

See http://www.w3.org/TR/xsl11/#d0e7194 for flow-map examples.

Unfortunately, I couldn't solve Tamsin's problem using flow-maps after
all: the best that I could do on the second page was to put A and B in
different regions, so it couldn't look like B directly followed A when A
overflowed onto the second page.

However, if A is always going to be large enough, and B is never going
to be small enough, that all of A and all of B can fit on one page, then
you can put B in a fo:block-container, specify a mimimum
block-progression-dimension, and set overflow to "repeat".  If the
minimum is larger than the maximum BPD that A will leave on the first
page, then B will always start on the second page, but if B overflows
that page, it will just generate more areas on the third page.  The
issue then becomes whether A will always leave enough room on the second
page for B's minimum BPD, otherwise B would start on the third page
instead of on the second page after the end of the large A.

------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xlink="http://www.w3.org/1999/xlink">
  <fo:layout-master-set>
    <fo:simple-page-master page-height="297mm" page-width="210mm"
margin-right="0.75in" margin-left="0.2in" margin-bottom="0.0in"
margin-top="0.375in" master-name="a">
      <fo:region-body margin-bottom="0.9in" margin-top="0.6in"
region-name="xsl-region-body"/>
    </fo:simple-page-master>
    <fo:page-sequence-master master-name="master">
      <fo:repeatable-page-master-reference  master-reference="a"/>
    </fo:page-sequence-master>
  </fo:layout-master-set>
    <fo:page-sequence master-reference="master">
      <fo:flow flow-name="xsl-region-body" font-size="72pt">
        <fo:block>A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A</fo:block>
        <fo:block-container overflow="repeat"
block-progression-dimension.minimum="200mm"><fo:block>B B B B B B B B B B B
B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
B</fo:block></fo:block-container>
      </fo:flow>
    </fo:page-sequence>
    <fo:page-sequence master-reference="master">
      <fo:flow flow-name="xsl-region-body" font-size="72pt">
        <fo:block>A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A</fo:block>
        <fo:block-container overflow="repeat"
block-progression-dimension.minimum="200mm"><fo:block>B B B B B B B B B B B
B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
B</fo:block></fo:block-container>
      </fo:flow>
    </fo:page-sequence>
</fo:root>
------------------------------------------------------------

Regards,


Tony Graham                         Tony.Graham@...
Director                                  W3C XSL FO SG Invited Expert
Menteith Consulting Ltd                               XML Guild member
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599   http://www.menteithconsulting.com
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
xmlroff XSL Formatter                               http://xmlroff.org
xslide Emacs mode                  http://www.menteith.com/wiki/xslide
Unicode: A Primer                               urn:isbn:0-7645-4625-2