incubator-odf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rob Weir <robw...@apache.org>
Subject Re: Retrieve current "Page Number" from an ODT
Date Wed, 09 May 2012 12:31:14 GMT
On Tue, May 8, 2012 at 3:53 PM, Kevin Skelton <Kevin_Skelton@mgic.com> wrote:
>  I understand that there is no true concept of a page number within an ODT,
> and I read the prior thread on this concept.

Correct.  Layout is done at runtime in an editor.  Page breaks are
sensitive to things line font metrics, line breaking algorithms,
"widow and orphan" calculations and other details of layout.

> However, I am wondering if there have been any enhancements to the API, or
> other tricks that could retrieve a relative page number on which an item
> resides.
>

In the general case, no.  You would need to simulate the layout of the
document, and that would be very difficult.

One possible workaround:   Some editors, like OpenOffice, write out  a
soft page using the <text:soft-page-break> element.  The intention of
this is to indicate where the page breaks were at the last time the
document was saved from the editor.  This is useful information to
some assistive technologies.  For example, a blind person can follow
along in a meeting reviewing a document with a reader, and when
someone says, "Now switch to page 11," they can follow.

So you might be able to scan for the soft page breaks and from those
determine the page numbers, as of the the last time the document was
saved.

Note: if you programmatically manipulate the document, with ODF
Toolkit, the soft page breaks could be misplaced.  For example, if you
insert a lot of new text.

> What I need to do is locate a Bookmark in an ODT (done), and  record what
> page this certain Bookmark resides in.  (Needed for page insertion later).
> I originally thought I could parse the <text:page-number> value, but this
> value is not tied to the "current page".
>

Another option, and a cleaner one if it solves your problem, is to use
a page number field:

http://incubator.apache.org/odftoolkit/simple/document/javadoc/org/odftoolkit/simple/common/field/Fields.html#createNextPageNumberField%28org.odftoolkit.odfdom.pkg.OdfElement%29

Fields are calculated at runtime, so they always reflect the current
layout.  They are the preferred way to refer to a page number in the
text of an ODF document.

Regards,

-Rob

> I do not see a way to do this.  If this can/cannot be done, please let me
> know.
>
> Thanks,
>
> Kevin Skelton
>
> This message is intended for use only by the person(s) addressed above and
> may contain privileged and confidential information. Disclosure or use of
> this message by any other person is strictly prohibited. If this message
> is received in error, please notify the sender immediately and delete this
> message.

Mime
View raw message