ASP.net and writer trouble getting pagecount into variable

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

ASP.net and writer trouble getting pagecount into variable

Postby justinparkes » Fri Apr 18, 2008 4:11 pm

Hi,
I am trying to get the page count of a document (openoffice) using asp.net but am having trouble converting the object to a string or integer. My code is below so if anyone can please please help I'd really appreciate it (my head is sore from all the banging I've been doing!)

Thanks

Code: Select all   Expand viewCollapse view
Dim oSM As Object 'Root object for accessing OpenOffice from VB
Dim oDesk, oDoc As Object 'First objects from the API
Dim oPageCount As Object
Dim _args As System.Array
Dim objDummy As Object = New Object
_args = System.Array.CreateInstance(objDummy.GetType, 0)
objDummy = Nothing ' free ressource
Try
oSM = CreateObject("com.sun.star.ServiceManager")
'Create the first and most important service
oSM.createInstance(com.sun.star.frame.Desktop)")
oDesk = oSM.createInstance("com.sun.star.frame.Desktop")

'Open an existing doc (pay attention to the syntax for first argument)
oDoc = oDesk.loadComponentFromURL("file:///" & filetoCount, "_blank", 0, _args)

oPageCount = oDoc.createInstance("com.sun.star.text.TextField.PageCount")

[b]Dim tmp As Object
Dim tmp2 As String
tmp = oPageCount -- {System.__ComObject} i need to get the value that is stored in here to pass it back to the calling procedure????
tmp2 = tmp.ToString() [/b]

'Close the doc
oDoc.Close(True)
oDoc = Nothing
Return tmp2
:end


The other alternative I have been thinking about is looping through the pages and manually incrementing a page count for example pseudo code
page = 1
while oDoc.jumptToNextPage
page = page + 1
loop

I just dont know how to program the while oDoc.jumptToNextPage bit - any ideas? I'd prefer to use the neater option in the Code above, but failing that??

Thanks for all help and hints
Last edited by RoryOF on Mon Sep 14, 2015 2:22 pm, edited 1 time in total.
Reason: Added [code] tags. [RoryOF, Moderator]
justinparkes
 
Posts: 7
Joined: Fri Apr 18, 2008 4:06 pm

Re: ASP.net and writer trouble getting pagecount into variab

Postby justinparkes » Fri Apr 18, 2008 9:13 pm

managed to get it done... if anyone is interested here is the code that got the count of the pages.

Code: Select all   Expand viewCollapse view
Dim oSM As Object 'Root object for accessing OpenOffice from VB
Dim oDesk, oDoc As Object 'First objects from the API

Dim _args As System.Array
Dim objDummy As Object = New Object
_args = System.Array.CreateInstance(objDummy.GetType, 0)
objDummy = Nothing ' free ressource
Try
'Instanciate OOo : this line is mandatory with VB for OOo API
oSM = CreateObject("com.sun.star.ServiceManager")
'Create the first and most important service
oDesk = oSM.createInstance("com.sun.star.frame.Desktop")

'Open an existing doc (pay attention to the syntax for first argument)
oDoc = oDesk.loadComponentFromURL("file:///" & filetoCount, "_blank", 0, _args)

Dim oCursor As Object
Dim pageCount As String
oCursor = oDoc.currentController.getViewCursor()
oCursor.jumpToLastPage()
pageCount = oCursor.getPage()

'Close the doc
oDoc.Close(True)
oDoc = Nothing
Return pageCount
Last edited by RoryOF on Mon Sep 14, 2015 2:23 pm, edited 1 time in total.
Reason: Added [code] tags. [RoryOF, Moderator]
justinparkes
 
Posts: 7
Joined: Fri Apr 18, 2008 4:06 pm


Return to External Programs

Who is online

Users browsing this forum: No registered users and 1 guest