We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Get the page number of a book mark

Hi,

I have inserted a number of book marks in my ASPOSE.WORD document. After pagination, I would like to iterate over the collection of bookmarks and get the page number for each bookmark.

Could you let me know how to do this please?

Regards, Paul.


This message was posted using Page2Forum from Controlling How Page Numbering is Handled - Aspose.Words for .NET

Hi

Thanks for your request. There is no direct method to get number of page where bookmark is located. However, you can try using code like the following to achieve this:

private int GetBookmarkPage(Bookmark bookmark)

{

// Create a DocumentBuilder and move it to the bookmark.

DocumentBuilder builder = new DocumentBuilder((Document)bookmark.BookmarkStart.Document);

builder.MoveToBookmark(bookmark.Name);

// Insert a PAGE field and update it.

Field page = builder.InsertField("PAGE");

page.Update();

int pageNumber = int.Parse(page.Result);

// Remove PAGE field.

page.Remove();

return pageNumber;

}

Hope this helps.

Best regards,

Hi,

Thanks for the code snippet. I have implemented it as below, but page.Result always evaluates to "", not a page number.

Regards, Paul.

-------------------------------------------------

var builder = new DocumentBuilder(asposeDoc);
foreach (Bookmark bookmark in bookmarks)
{
if (bookmark.Name.StartsWith("CaseLinesBookmark"))
{
builder.MoveToBookmark(bookmark.Name);
var page = builder.InsertField("PAGE");
page.Update();
int pageNumber = 0;
var success = int.TryParse(page.Result, out pageNumber);
page.Remove();
}
}

Hi

Thanks for your request. Which version of Apsose.Words do you use? Have you tried calling UpdatePageLayout before updating field:

// Insert a PAGE field and update it.

Field page = builder.InsertField("PAGE");

builder.Document.UpdatePageLayout();

page.Update();

Hope this helps.

Best regards,

That’s great and works well. Thanks.

The issues you have found earlier (filed as WORDSNET-2978) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(60)