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

Free Support Forum - aspose.com

Document Page No Issue

Hi,
I am getting the page number by using the bookmark but it is not returning the correct count i.e. in my original document for eg : if bookmark text is on page number 16 the result from your Aspose.Words dll (version 16.1.0.0) is returning 15. I am getting these types of discrepancies in my result.

As I am using below code to get page number:

DocumentBuilder builder = New DocumentBuilder(document);
builder.MoveToDocumentStart();               
builder.MoveToBookmark(bookmarkName);                
var page = builder.InsertField("PAGE");
builder.Document.UpdatePageLayout();
page.Update();
int pageNumber = CommonFunctions.ConvertToInt(page.Result);                
page.Remove();
return pageNumber;

Please suggest that how can resolve this issue.

@RiteshK10 You can use LayoutCollector to get page number:

Document doc = new Document(@"C:\Temp\TableHeading.docx");
LayoutCollector collector = new LayoutCollector(doc);

// get bookmakrk.
Bookmark bk = doc.Range.Bookmarks["myBookmakrk"];

// Get page index where bookmakr start is located.
Console.WriteLine(collector.GetStartPageIndex(bk.BookmarkStart));

The problem on your side also might occur, for example, because the fonts used in your original document are not available in the environment where document processing is performed. To calculate page index, Aspose.Words needs to build document layout and the fonts are required for this. If Aspose.Words cannot find the font used in the document, the font is substituted. This might lead into fonts mismatch and document layout differences and as a result incorrect page number returned. You can implement IWarningCallback to get notifications when font substitution is performed.

Also, you are using quite old version of Aspose.Words, which was released more than 6 years ago. I would suggest you use the latest 22.9 version.
If the problem still persist, please attach your document here for testing, we will check it on our side and provide you more information.

Hi Team,

As suggested below, for wrong page number on Bookmark we need to use latest version.

Can you please suggest how can we use trial version of the suggested version, to check if it can fix the issue before going to purchase the latest version.

Thanks

Biswarup

~WRD0002.jpg (357 Bytes)

@biswarup You can request a temporary 30-days license to test the latest version of Aspose.Words without evaluation version limitations.

Hi Team,

Finally, I am able to use trial license for Aspose.Words and able to use latest version (22.10.0), but still getting wrong page numbers for Bookmarks.

Would appreciate your help in fixing this issue, we have been facing this issue since quite a long time.

Please note, this is on random documents, also please let us know if we need to share any such sample documents.

Code snippet we are using to get page number for bookmarks:

builder.MoveToDocumentStart();
builder.MoveToBookmark(“bookmarkName”);
var page = builder.InsertField("PAGE");
builder.Document.UpdatePageLayout();
page.Update();
int pageNumber = Convert.ToInt32(page.Result);
page.Remove();

Thanks

Biswarup

@biswarup Please try using the following code to get page number where the bookmark is located:

Document doc = new Document(@"C:\Temp\TableHeading.docx");
LayoutCollector collector = new LayoutCollector(doc);

// get bookmakrk.
Bookmark bk = doc.Range.Bookmarks["myBookmakrk"];

// Get page index where bookmakr start is located.
Console.WriteLine(collector.GetStartPageIndex(bk.BookmarkStart));

Also, please make sure the fonts used in the document are available in the environment where the document processing is performed as I mentioned in this answer:
https://forum.aspose.com/t/document-page-no-issue/252595/2

Hi Team,

Applied the below code snippet, on most cases it is returning wrong page number. Can you please suggest any other alternative solution.

Thanks

Biswarup

@biswarup Could you please attach your document here for testing? We will check the issue and provide you more information. You should note that MS Word documents are flow document and does not contain any information about document layout. Document is layout into pages by the consumer application on the fly. So to calculate page index, Aspose.Words needs to build document layout and the fonts are required for this. Fi the fonts are not availabe the layout might be inaccurate.

Hi,

The sample docs which are having issues are client documents, will try to compile a sample doc and will share the same.

Thanks

Biswarup

1 Like

Hi Team,

PFA the sample document, which is having page number issues,

PFB the discrepancies on bookmark page number,

(Attachment Draft Report-TST006508.Docm is missing)

Attaching .docx as .docm is not authorized.

Thanks

Biswarup

Draft Report-TST006508.Docx (183 KB)

@biswarup Thank you for additional information. Could you please also specify for which bookmark page number is returned improperly? There are 94 bookmarks in your document.
Also, upon building layout the following fonts are substituted in your document on my side:

Font 'Open Sans' has not been found. Using 'Segoe UI' font instead. Reason: alternative name from document.
Font 'Myriad Pro' has not been found. Using 'Arial' font instead. Reason: alternative name from document.
Font 'Helvetica' has not been found. Using 'Arial' font instead. Reason: table substitution.
Font ' Helvetica' has not been found. Using 'Times New Roman' font instead. Reason: default font substitution.

Font substitution might lead into document layout differences and as a result incorrect page numbers returned by LayoutCollector.

Hi Alexey,

I mentioned in my mail for which we have the page number issue, anyway sharing it again, PFB.

Draft Report-TST006508.Docx (183 KB)

@biswarup As I mentioned the following fonts used in your document are not available on my side:

  • Open Sans
  • Myriad Pro
  • Helvetica

The font substitution might lead into document layout difference and as a result incorrect page numbers. Could you please attach these fonts here for testing? We will check the issue and provide you more information.

Hi Alexey,

Thanks for update…

PFA the fonts, checked with the fonts but for the attached file still having issues as below (for other docs page number is coming fine),

Font.zip (15 MB)

(Attachment Draft Report-TST006492.Docm is missing)

Sending again as the previous mailed was not delivered…

Font_Share.zip (385 KB)

(Attachment Draft Report-TST006492.Docm is missing)

Sending again as the previous mailed was not delivered…

Draft Report-TSH025313_1.Docx (173 KB)

Font.zip (15 MB)

@biswarup Thank you for additional information. I ha managed to reproduce the problem on my side. For a sake of correction it has been logged as WORDSNET-24564. We will keep you informed and let you know once it is resolved.

Hi Alexey,

This issue will be addressed in Aspose latest version, or we can use it our current version (16.10) using a hotfix.

Also please share if there is any update, as we are stuck in Production because of this issue.

Thanks

Biswarup

@biswarup All fixed and improvements are always added into new versions of Aspose.Words. No hotfixes for old version are provided.

The issue is currently in the queue for analysis. Once analysis is complete we will be able to provide you more information.