Page 1 of 1

Updating Page Number of TOc

PostPosted: Mon Apr 02, 2012 10:28 pm
by sureshbabubv
Hi Jason,

I am having a table of contents, in that on I have some hyper links which points to their related book marks in the document.

When I manually click on the TOC and asking to updatefield, it is updating to right page number. but I would like to do it programatically, can you please advice me how to do this.


I found some code in a .net application as shown in the following url

http://www.samuraiprogrammer.com/blog/2 ... pened.aspx

can you please advice me how to do this by docx4j.

Thanks & Regads,
B.V.Suresh Babu.

Re: Updating Page Number of TOc

PostPosted: Mon Apr 02, 2012 11:07 pm
by jason
There are earlier posts on this topic, but in a nutshell, docx4j can't update the page numbers without a page layout model which would determine what content goes on what page.

If you are opening the document in Word, you can have a macro which runs automatically on open, but this has issues of its own...

Re: Updating Page Number of TOc

PostPosted: Tue Apr 03, 2012 12:00 am
by sureshbabubv
Hi Jason,

thanks for your quick reply.

I used the following code

Code: Select all

DocumentSettingsPart dsp = wordMLPackage.getMainDocumentPart().getDocumentSettingsPart();

CTSettings objCTSettings = dsp.getJaxbElement();


BooleanDefaultTrue b = new BooleanDefaultTrue();
b.setVal(true);
objCTSettings.setUpdateFields(b);
 

dsp.setJaxbElement(objCTSettings);
wordMLPackage.getMainDocumentPart().addTargetPart(dsp);




but the problem, that I am getting is while opening the generated document, it is asking for confirmation to refresh the indexes or not.

It is updating the page numbers but it is showing "1" as page number for all toc links as shown in the attached document.

Thanks & Regards,
B.V.Suresh Babu.