Apache OpenOffice (AOO) Bugzilla – Issue 100662
Writer: Incorrect number of pages and hidden property
Last modified: 2017-05-20 11:28:04 UTC
I'm using following code (C#) to determine the number of pages in doc and docx files: Code: public static short GetPageCount(string path) { if (_componentLoader == null) Initialize(); XComponent xComponent = null; int counter = 0; while (xComponent == null) { try { string url = _urlConverter.getFileURLFromSystemPath (Path.GetPathRoot(path), path); xComponent = _componentLoader.loadComponentFromURL (url, "_blank", 0, new PropertyValue[] { MakePropertyValue("Hidden", new uno.Any (true)) }); } catch (DisposedException) { if (counter >= _maxRetries) throw; Thread.Sleep(200 * counter); Initialize(); } finally { counter++; } } XTextDocument doc = (XTextDocument)xComponent; XController controller = doc.getCurrentController(); XPageCursor cursor = (XPageCursor)((XTextViewCursorSupplier) controller).getViewCursor(); cursor.jumpToLastPage(); short result = cursor.getPage(); return result; } The purpose of Initialize and MakePropertyValue methods is evident. Result is sometimes different then the actual number of pages (as rendered by swriter). The only workaround I've found is not specifying Hidden property when loading xComponent. It's not acceptable for many reasons.
jsc -> od: after discussion with mba to you
Looks like commenting 'MakePropertyValue("Hidden", new uno.Any (true))' out doesn't resolve docx issue completely, but only reduces number of documents it's reproducible on
Reset assigne to the default "issues@openoffice.apache.org".