Hi Aaron,

Le jeudi 09 avril 2009 à 13:36 -0400, Aaron Ehrensberger a écrit :
> Can anybody help me use the API?
> 
> There is a service called com.sun.star.text.TextField.PageCount -
> http://api.openoffice.org/docs/common/ref/com/sun/star/text/textfield/Pa
> geCount.html - that says it should show me the page count of the
> document.  
> 
> However, I can't figure out how to get the value of the page count.  I
> believe it's a short, but how do I cast it, retrieve it, etc...?
> 
> I've tried this, to no avail...
> 
> Object pageCount =
> xDocMSF.createInstance("com.sun.star.text.TextField.PageCount" );
>  
> XPropertySet pageCountPS = (XPropertySet) UnoRuntime.queryInterface(
> XPropertySet.class, pageCount );

As you were already been told, this is not the right mailing list for
API related questions, but here is an answer.

The service you are talking about is the service for the PageCount field
that you can insert in the document. Inserting a field to get the page
count of the document isn't the easiest way. Here is a small snippet
showing how to do it:

XModel xModel = (XModel)UnoRuntime.queryInterface( 
        XModel.class, xDocMSF );
XPropertySet xViewProps = (XPropertySet)UnoRuntime.queryInterface( 
        XPropertySet.class, xModel.getCurrentController( ) );
Object oCount = xViewProps.getPropertyValue( "PageCount" );
long nNbPages = AnyConverter.toLong( oCount );

Hope that helps,

-- 
Cédric Bosdonnat
OOo Eclipse Integration developer
http://cedric.bosdonnat.free.fr



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to