OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Problem with Ruby and COM-UNO bridge

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
JulianUK
Newbie
Newbie


Joined: 29 Mar 2005
Posts: 3

PostPosted: Tue Mar 29, 2005 9:56 am    Post subject: Problem with Ruby and COM-UNO bridge Reply with quote

I've been trying to drive OOO from Ruby to automate a bunch of document conversions.

Having researched on the web, including here here and here I tried the code below, however whenever I try to save the document with parameters (to set an output filter) I got an error from the bridge.

This is with OOO 1.1.4 and has happened on both W98 and XP.

I tried a quick test using VBScript (fundamentals copied from here) and got the same erors, suggesting it is a bridge problem rather than Ruby.

Any ideas anyone?

Code:

require 'win32ole'
   
$serviceManager = WIN32OLE.new("com.sun.star.ServiceManager")
$desktop = $serviceManager.createInstance("com.sun.star.frame.Desktop")
   
def newWriterDocument()
    document = $desktop.loadComponentFromURL("private:factory/swriter",\"_blank", 0, [])
   document
end
   
def test()
   filter = "writer_pdf_Export"
   fprops = makeProperties("FilterName" => filter)
   document = newWriterDocument
   text = document.GetText
   cursor = text.createTextCursor
   text.insertString(cursor, "Hello World", 0)
   oURL = "file:///c|/test.pdf"
   document.storeAsUrl(oURL, fprops) # this line fails with OLE error
   #store a document in standard format - document.storeAsUrl(oURL, []) - works
end
   
def makeProperty(name, value)
   property = $serviceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
   property["Name"] = name
   property["Value"] = value
   property
end
   
def makeProperties(hash)
   properties = []
   hash.each { | key, value |
   properties < < makeProperty(key, value)
     }
   properties
end
   
begin
  test
rescue
   
ensure
   
end
Back to top
View user's profile Send private message
hol.sten
Super User
Super User


Joined: 14 Nov 2004
Posts: 3385
Location: Hamburg, Germany

PostPosted: Tue Mar 29, 2005 12:48 pm    Post subject: Re: Problem with Ruby and COM-UNO bridge Reply with quote

JulianUK wrote:
Any ideas anyone?

Yes!

JulianUK wrote:
Code:
oURL = "file:///c|/test.pdf"
   document.storeAsUrl(oURL, fprops) # this line fails with OLE error

This problem is quite often reported in this forum. You can rewrite this error in all possible languages that are supported bei UNO Wink

To solve the problem, use "storeToUrl" instead of "storeAsUrl". I fixed this problem myself with Java. Look for example at this link: http://www.oooforum.org/forum/viewtopic.phtml?t=13925&highlight=pdf+storetourl

With kind regards
hol.sten
Back to top
View user's profile Send private message
JulianUK
Newbie
Newbie


Joined: 29 Mar 2005
Posts: 3

PostPosted: Tue Mar 29, 2005 1:14 pm    Post subject: Re: Problem with Ruby and COM-UNO bridge Reply with quote

hol.sten wrote:

Yes!

This problem is quite often reported in this forum. You can rewrite this error in all possible languages that are supported bei UNO Wink

To solve the problem, use "storeToUrl" instead of "storeAsUrl". I fixed this problem myself with Java. Look for example at this link: http://www.oooforum.org/forum/viewtopic.phtml?t=13925&highlight=pdf+storetourl

With kind regards
hol.sten


many thanks!

is this bug documented anywhere at OO do you know?

regards

Julian
Back to top
View user's profile Send private message
hol.sten
Super User
Super User


Joined: 14 Nov 2004
Posts: 3385
Location: Hamburg, Germany

PostPosted: Tue Mar 29, 2005 1:27 pm    Post subject: Re: Problem with Ruby and COM-UNO bridge Reply with quote

JulianUK wrote:
is this bug documented anywhere at OO do you know?

Regarding all those threads about this pdf "problem", it's not a bug, it's a feature. The function "storeAsURL" is equivalent to "Save as..." of OOo. You can save this way all the formats that OOo can import. Another function is "storeToURL". You can use it for formats that OOo can't import. It's not the "Save as..." but the "Export..." feature.

With kind regards
hol.sten
Back to top
View user's profile Send private message
JulianUK
Newbie
Newbie


Joined: 29 Mar 2005
Posts: 3

PostPosted: Tue Mar 29, 2005 1:56 pm    Post subject: Re: Problem with Ruby and COM-UNO bridge Reply with quote

hol.sten wrote:

Regarding all those threads about this pdf "problem", it's not a bug, it's a feature. The function "storeAsURL" is equivalent to "Save as..." of OOo. You can save this way all the formats that OOo can import. Another function is "storeToURL". You can use it for formats that OOo can't import. It's not the "Save as..." but the "Export..." feature.
With kind regards
hol.sten


Thanks - I bet it isn't described as simply as that anywhere in the OO documentation!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group