PageCursor Reporting Wrong Page Number

Java, C++, C#, Delphi, ??? - Using the UNO bridges

PageCursor Reporting Wrong Page Number

Postby msmith68 » Fri Jun 06, 2008 3:13 pm

We have a Windows C++ application that uses UNO API to open an ODT file and convert it to a PDF. I am trying to add a new feature that will sort the PDF files being create by number of pages, putting PDFs with the same number of pages in the same subdirectory. I thought the easiest way to do this would be to get a page count from Writer before doing the conversion. The only way I found to do this was to get a Page cursor, jump to the last page of the document and then get the page number from the cursor. This seemed to work when I stepped through the code in the debugger. But when I run this code full speed, I get the wrong page number, the Page cursor comes back with page number 7 in my 5 page test document. If I put in a 3 second delay (Sleep(30000)) anywhere between the opening of the document and the getPage on the Page cursor the Page number retrived is correct. Delays less than about 2.5 seconds don't help. Here is the code I am running:

Reference< XComponent > xComponent = xComponentLoader->loadComponentFromURL(OUString::createFromAscii(pszFileName),
OUString( RTL_CONSTASCII_USTRINGPARAM("_blank")), 0, loadProps);
Reference < XModel > xModel(xComponent, UNO_QUERY_THROW);
Reference < XController > xController = xModel->getCurrentController();
Reference < XTextViewCursorSupplier > xViewCursorSupplier (xController, UNO_QUERY_THROW);
Reference < XTextViewCursor > xViewCursor = xViewCursorSupplier->getViewCursor();
Reference < XPageCursor > xPageCursor (xViewCursor, UNO_QUERY_THROW);
xPageCursor->jumpToLastPage();
iPage = xPageCursor->getPage();

Any idea why this is happening? It seems like something asynchronous is going on after the loadCompoentFromURL that needs complete before the PageCursor can work correctly. If that is the case how do I know when that activity is complete so I can be sure that the page number I am getting from the cursor is accurate?

Mike
msmith68
 
Posts: 3
Joined: Wed May 28, 2008 3:35 pm

Re: PageCursor Reporting Wrong Page Number

Postby ms777 » Sat Jun 07, 2008 5:14 pm

msmith68 wrote:... how do I know when that activity is complete ...


The answer is short, but frustrating: You don't. See http://www.oooforum.org/forum/viewtopic ... ght=timing and numerous other topics on this topic in the same forum.

If you find a workaround please let us know.

Good luck,

ms777
ms777
Volunteer
 
Posts: 134
Joined: Mon Oct 08, 2007 1:33 am

Re: PageCursor Reporting Wrong Page Number

Postby javabuh » Fri Jun 15, 2012 1:07 am

Hello

I had the same problem when I change OpenOffice 2.4 on Debian to new version OpenOffice 3.5. When i want to print document application get me wrong page count. For exaple I print document which has 10 pages, but OpenOffice tell me that document has 15 pages when i print document there were a blank pages.

At first a try to put delay between getDocument() and getController it works, but printing took long time. I started search where the problem is and I found that soffice.bin is to slow when formatting document but CPU was only at 50% and sometimes did nothing. Finally problem was in the way how my application was connected to OpenOffice. I used socket version when I changed to pipe version, suddenly OpenOffice get correct pages count without any delay.
OpenOffice 3.4, OpenOffice 2.1 OpenOffice 2.4 on Windows 7, Debian 6, Debian 4
javabuh
 
Posts: 1
Joined: Fri Jun 15, 2012 12:54 am


Return to External Programs

Who is online

Users browsing this forum: No registered users and 3 guests