Forum How do I...?

Detect pagebreak?

I have the content of a block level div that is breaking inside automatically. This is desired. However, is there anyway I can identify when this happens?

The section is titled "Remarks" and on the new page, I would like the section to be "Remarks (continued)".

The only way to do this at the moment is to use a table caption:
<caption style="prince-caption-page: first">Remarks</caption>
<caption style="prince-caption-page: following">Remarks (continued)</caption>
<td>...content goes here...</td>

In the future we may add a method of doing this for arbitrary blocks.
Is this still the case, or are there new ways to detect page breaks in the current version of Prince?
Not yet. What kind of use case did you have in mind?
I have a similar problem as wilby's in an Annual Report i'm working on:

There is a 30-some-page section of notes to the financial statements, with deeply nested numbering structure (e.g. Note – Impaired loans and advances an non-trading investments).

If a note is broken over two pages, there (legally!) needs to be a mention on the following page :

Note … (continued)

I have seen reports where the whole numbering tree is mentioned:
Note 4… Bla (continued)
Note 4.3… Bla foo (continued)
Note 4.3.2… Bla foo bar (continued)
Note… Bla foo bar whatever (continued)"

I have tried cheating on this by using something like the following construction, but it's not *quite* working the way it needs to.

.noteTitle { string-set: noteHeader content() }

@page Notes { 
	@top-left {
		content: "Notes to the financial statements: " string(noteHeader);

I'll try working with the "prince-caption-page: following" property to see if I can improvise something.

I'll also put some though into the matter, and also try to collect a few examples of applications and strage edge cases. Conceptually, this situation is also complicated by CSS's lack of a 'previous' or 'parent' selector (the opposite of the 'child' and 'adjacent' selector).

IMO this is a job for javascript/jquery, but there would need to be some way of detecting page breaks to act on them…
Right, this is a very reasonable thing to want to do, but it's getting beyond what CSS can currently express. I think we're going to need to design some new styling mechanisms to enable this, maybe for Prince 10. :D
Well, if there were some way to hook pagebreaks in javascript/jquery, it would be possible, at least.

Any ideas on how this could be approached?
Like you said, one way of approaching it would be to add more JavaScript hooks into the layout engine. At the moment, JavaScript can only be called before layout, and in limited situations like prince-script() for generated content.

However, it might be conceptually simpler to introduce new CSS pseudo-elements, like ::before-break and ::after-break, that can add generated content around page breaks.
Any chance that there are solutions to detect page breaks in Prince now?
Yes, although it's still a little clumsy: it requires running JavaScript after layout has finished, checking the generated box tree, and then re-running Prince using that information.

This two-pass approach is now described in the documentation and there is an example here.
Any Updates on how to detect the pagebreak?

Really want to add a header in an element after the running header.

Is the two-pass approach still the best solution?
The Two-Pass solution has been improved with a single pass - but you need to use the latest builds, and documentation is not completely ready yet. For a start, you can try to see if you can adapt the other instructions to serve your purpose.