[Solved] Getting Total Page Count for text document

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
dvcroft
Posts: 3
Joined: Fri Dec 12, 2008 2:25 am

[Solved] Getting Total Page Count for text document

Post by dvcroft »

I need to know the page count of a document. I see there is a PageCount property in TextDocumentView, but on the getPropertyValue() in the code below I get com.sun.star.beans.UnknownPropertyException.

Code: Select all

    XViewSettingsSupplier xViewSettings = (XViewSettingsSupplier) UnoRuntime.queryInterface(XViewSettingsSupplier.class,xcontroller);
    XPropertySet viewSettings=xViewSettings.getViewSettings();
    Object o=viewSettings.getPropertyValue("PageCount");
Note the following code and output.

Code: Select all

      XServiceInfo factory = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, xcontroller);
      String[] availableServiceNames = factory.getSupportedServiceNames();
      for (String string : availableServiceNames) {
          System.out.println(string);
      }

output:
com.sun.star.text.TextDocumentView
com.sun.star.view.OfficeDocumentView
Last edited by dvcroft on Thu Sep 27, 2012 5:21 pm, edited 1 time in total.
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Getting Total Page Count for text document

Post by hanya »

Query XPropertySet interface from xcontroller and get PageCount property from it.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
FJCC
Moderator
Posts: 9277
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Getting Total Page Count for text document

Post by FJCC »

The PageCount is part of the CurrentController, not part of the ViewSettings. I used MRI to record the following Java code to get the PageCount.

Code: Select all

import com.sun.star.beans.UnknownPropertyException;
import com.sun.star.beans.XPropertySet;
import com.sun.star.frame.XController;
import com.sun.star.frame.XModel;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.UnoRuntime;

static public void snippet(Object oInitialTarget)
{
	try
	{
		XModel xModel = UnoRuntime.queryInterface(
			XModel.class, oInitialTarget);
		XController xController = xModel.getCurrentController();
		
		XPropertySet xPropertySet = UnoRuntime.queryInterface(
			XPropertySet.class, xController);
		int nPageCount = AnyConverter.toInt(xPropertySet.getPropertyValue("PageCount"));
		
	}
	catch (WrappedTargetException e1)
	{
		// getPropertyValue
		e1.printStackTrace();
	}
	catch (IllegalArgumentException e2)
	{
		// 
		e2.printStackTrace();
	}
	catch (UnknownPropertyException e3)
	{
		// getPropertyValue
		e3.printStackTrace();
	}
}
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
dvcroft
Posts: 3
Joined: Fri Dec 12, 2008 2:25 am

Re: [Solved] Getting Total Page Count for text document

Post by dvcroft »

Thanks to Hanya and FJCC for the quick help! Worked just as desired.
OOo 2.3.X on openSuse 10
Post Reply