Page 1 of 1

TOC page numbers

PostPosted: Thu Sep 30, 2010 12:48 am
by Nian
3. Is it possible to generate "page number"(page reference) in TOC automatically?
The topic "Creating TOC" mentioned an approach to generate TOC.
Is it including generating the page number in TOC?
or just the linkage of the Headings to the TOC (i.e anchor)?

I think the page number is generated while word open the file,
so, is it possible to get those page numbers while generating word file?!


Sorry for the poor English,
and any advice would be appreciated.

Re: TOC page numbers

PostPosted: Thu Sep 30, 2010 9:02 am
by jason
Currently, it is left up to Word to generate the page numbers from the field code.

What is your use case for requiring the page numbers to be generated also?

(This is tricky, since it would require docx4j to have a page layout model, and if the page numbers are to be accurate, one which is identical to Word's)

With minor enhancements, we could probably put a table of contents in the PDF output.

The HTML output could also contain a table of contents easily enough (omitting page numbers).

Re: TOC page numbers

PostPosted: Thu Sep 30, 2010 10:17 pm
by Nian
Hi Jason,

It's my fault, I haven't read the topic "Table of contents" till this morning.

I just hope the page number will apear automatically while user open the docx,
and I found it could be achieved by following steps:

1. insert the field code in document.xml
2. set the dirty attributes in fdr elements or set the UpdateField element in setting.xml to true.

then, when I open the docx, the page number will be calculated by word.

But there is one problem remaining,
after setting the attributes and open the word file,
there will be a dialogue shows up to ask me whether do I want to update all the field codes in the file.

And all the field codes will be updated if I clicked Yes.
(TOC is included, of course!)

Is there any method to turn off this dialogue before it shows up?
User will never be satisfied even just a single tiny dialogue.....

Thanks again!!

Re: TOC page numbers

PostPosted: Fri Oct 15, 2010 9:25 am
by alan
Do you think you could share your TOC code.

I've managed to get a TOC working, but using a very long winded approach, for the moment :=
Opening an existing Document
Adding new information, including TOC bookmarks
Saving the Document
Re-opening the Document
marshaltoString
Navigating to pre-defined Text
Replacing the Text with the TOC
unmarshalString
Saving the Document

I assume that I should be able to navigate to a point in the doc, using xpath and add the TOC, without resorting to marshal & unmarshal.
It's not clear how I add the TOC to the doc once I've located the insertion point.
Any help welcome
Many thanks
alanowenuk@yahoo.co.uk

Re: TOC page numbers

PostPosted: Wed Oct 20, 2010 2:05 pm
by jason
Nian wrote:Is there any method to turn off this dialogue before it shows up?
User will never be satisfied even just a single tiny dialogue.....


An autoexec or autorun macro? see http://support.microsoft.com/kb/286310

To avoid a "do you want to run the macro message", you'll need to run from a trusted location, or sign it (and set Trust Center Settings).