-
Notifications
You must be signed in to change notification settings - Fork 460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AppProperties.Pages() doesn't always return the correct number of pages #496
Comments
Welcome! Thanks for posting your first issue. The way things work here is that while customer issues are prioritized, |
The issue with getting the actual page number is because it could only properly calculated when opening the document from an app such as MS Word or others because the document file itself didn't contain any kind of info related to pages other than the one available in the document properties which is returned by To work around this, in UniOffice v1.31.0 that released recently we introduced an experimental function You could use the new method just like this: doc, err := document.Open("9pages.docx")
if err != nil {
log.Fatalf("error opening document: %s", err)
}
defer doc.Close()
fmt.Println("Total number of pages in the document from properties:", doc.AppProperties.Pages())
actualCount, err := utils.GetNumPages(doc)
if err != nil {
log.Fatalf("error calculating page count: %s", err)
}
fmt.Println("Total number of pages in the document from calculation:", actualCount)
doc.AppProperties.SetPages(int32(actualCount))
fmt.Println("Total number of pages in the document from properties:", doc.AppProperties.Pages()) This method is currently marked as an experimental because the conversion result itself probably produces an incorrect result. Additionally, we also introduced a new method If by some chances the result of |
Description
I'm trying to get the page count of several office documents. However I've noticed that not all of them return the correct page count.
It seems that in the documentation it mentions "Pages returns total number of pages which are saved by the text editor which produced the document. For unioffice created documents, it is 0.", could this be related to that?
If so, which method can I use to get a consistent correct count?
Expected Behavior
Document "2pages.docx" should print 2
Document "9pages.docx" should print 9
Actual Behavior
Document "2pages.docx" prints 0
Document "9pages.docx" prints 3
Code and Documents
2pages.docx
9pages.docx
The text was updated successfully, but these errors were encountered: