Not returning the correct page number using bookmark object

I am using Office 365

Please find the attached screenshot

image.png (189.3 KB)

And also find the attached document in pdf
file-sample_1MB.pdf (27.1 KB)
as you mentioned

@gaurav.budhiraja Thank you for additional information. Which of the attached documents do you use for testing? If I open file-sample_1MB.docx I see the same picture as yours, but this document does not have PNT_Main_029_1 bookmark. If I check TestDoc.docx it looks like on the screenshot I have attached in my previous answer. This document has PNT_Main_029_1 bookmark and it is on the second page.

Hi @alexey.noskov,

I have shared the document without bookmark and now please find the attached document with bookmark addedfile-sample_1MB.docx (1.4 MB) and testdoc.docx is the converted document using aspose code.

Please let me know for any query.

@gaurav.budhiraja Tested with newly attached document and Aspose.Words returns correct page number for PNT_Main_029_1 bookmark:

PNT_Main_029_1 - start 1; end 1

And PDF produced by Aspose.Words looks exactly the same as PDF produced on your side using MS Word: out.pdf (80.2 KB). So Aspose.Words builds correct layout of this document.

@alexey.noskov , i have used below code for creating document using aspose and then saving it and it results me to a document having page count 4.

        var document = new Document(new MemoryStream(documentContents));
        GetSubstitutionWithoutSuffixes(document);


        int d = document.PageCount;

        document.Save("TestDoc.docx", SaveFormat.Docx);

@alexey.noskov

Are you using same code for saving document or any else parameter is missing while saving. can you please let me know ?

@gaurav.budhiraja I have used this code:

Document doc = new Document(@"C:\Temp\in.docx");
doc.Save(@"C:\Temp\out.pdf");

What does GetSubstitutionWithoutSuffixes method do in your code?

@alexey.noskov,

GetSubstitutionWithoutSuffixes method is used for the warnings which is used while font substitutions and it implements Iwarning interface.

Please let me know for any query

@gaurav.budhiraja Please make sure you are using the correct document as an input. Just save the document from input stream to file next to the output produced by Aspose.Words and compare the documents. I suspect you are using different documents for testing and for checking in MS Word.

@alexey.noskov : now i am getting the correct page numbering for the simple doc . Now i will with the document with tables and images and if face any issue then let you know.

Thanks

1 Like

Hi @alexey.noskov,

still there is issue of page numbering in one my sample testing document.

Please find the attached document and the result and the snapshot of the issue .

image.png (5.5 KB)

file-sample_1MB.docx (1.0 MB)
DiscripencyResult.docx (14.1 KB)

@gaurav.budhiraja Upon processing your document I see the following warnings:

Font 'Liberation Sans;Arial' has not been found. Using 'Arial' font instead. Reason: alternative name from document.
Font 'DejaVu Sans' has not been found. Using 'Verdana' font instead. Reason: alternative name from document.
Font 'Open Sans;Arial' has not been found. Using 'Segoe UI' font instead. Reason: alternative name from document.
Font 'Droid Sans Fallback' has not been found. Using 'Times New Roman' font instead. Reason: font info substitution.
Font 'Droid Sans Fallback' has not been found. Using 'Times New Roman' font instead. Reason: font info substitution.
Font 'Liberation Serif;Times New Roma' has not been found. Using 'Times New Roman' font instead. Reason: alternative name from document.
Font 'Liberation Serif;Times New Roma' has not been found. Using 'Times New Roman' font instead. Reason: alternative name from document.

As you can see some of fonts used in your document are not available on my side and are substituted. This leads into layout differences as I already mentioned earlier. To get accurate document layout you should either install the missed fonts or put them into the folder and use this folder as fonts source.

Hi @alexey.noskov,

After installing the fonts the issue is fixed and now i am getting correct page numbering

Thanks

1 Like