[Solved] Breaking links and emedding images into odt from VB

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
z12t34
Posts: 13
Joined: Thu Oct 15, 2009 12:21 am

[Solved] Breaking links and emedding images into odt from VB

Post by z12t34 »

Hi to everyone,

I have been working on the VB application that generates the HTML output on some physical calculations. I have managed to open the HTML in OpenOffice swriter application and to save it in .odt file format, but now I have one serious problem.

I need to break all links from the HTML and to embed all images in .odt document. So, the problem now comes down to the simple breaking all links in existing .odt document and embedding images into document from VB.

I have found some unplublished api-s in the 3.1.1. sdk but it seems that they are not working. Maybe somebody have an idea of the solution for this problem?

Thnx in advance :-)
Last edited by z12t34 on Thu Oct 29, 2009 12:08 am, edited 2 times in total.
OpenOffice 3.1. on XP
z12t34
Posts: 13
Joined: Thu Oct 15, 2009 12:21 am

Re: Breaking links and emedding images into document from VB

Post by z12t34 »

Heh... I still waiting for someone to help :-(((

I have tried to save a macro which does open the Link dialog and breaks all linsk, but if try to run the sam code from VB, only the dialog is displayed, and nothing else happend.

Does anyone have the idea of how to break all links form VB?
OpenOffice 3.1. on XP
User avatar
Hagar Delest
Moderator
Posts: 32667
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Breaking links and emedding images into document from VB

Post by Hagar Delest »

I move your topic in the Macros forum. Perhaps you'll get more luck there.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
rudolfo
Volunteer
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: Breaking links and emedding images into document from VB

Post by rudolfo »

You say you have saved a macro that breaks all links ... does this mean that you used the macro recorder for this?
It's not clear from your post if the problem is that this saved Macro does not run from Visual Basic or if this macro does not run at all?
You should not expect that we all speak MS Visual Basic fluently here. But if you have a piece of code in OOo Basic, we can try to help you if you publish the critical parts of the code here.
Generally the macro should rely widly on methods and properties of some of the writer objects. In other words it will look the same no matter what kind of macro language you use (OOo Basic, Python and the UNO bridge, Visual Basic with the ActiveX automation bridge).
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Breaking links and emedding images into document from VB

Post by B Marcelly »

Hi,
I found a solution for Writer, on version 3.1. Here it is, as a subroutine in OOoBasic:

Code: Select all

Sub embedImagesInWriter(doc as Object)
Dim allImages As Object, imageX As Object
Dim x As Long

allImages = doc.GraphicObjects
for x = 0 to allImages.Count -1
  imageX = allImages.getByIndex(x)
  if InStr(1, imageX.GraphicURL, "vnd.sun.star.GraphicObject:", 0) = 0  then
    imageX.Graphic = getGraphicFromURL(imageX.GraphicURL)
  end if
next
End Sub


'   This code is provided by Ariel Constenla-Haile, see
'   http://www.mail-archive.com/dev@api.openoffice.org/msg09255.html 

Function getGraphicFromURL( sURL as String) as com.sun.star.graphic.XGraphic
        On Error Resume Next
        Dim oGraphicProvider as Object
        oGraphicProvider = createUnoservice("com.sun.star.graphic.GraphicProvider")
        
        Dim aMediaProperties(0) as New com.sun.star.beans.PropertyValue
        aMediaProperties(0).Name = "URL"
        aMediaProperties(0).Value = sURL

        getGraphicFromURL = oGraphicProvider.queryGraphic(aMediaProperties)
End Function
It really embeds image files in the document (contrary to user interface Edit > Links which converts jpg images to png, see issue 15508).
I could not find the equivalent for Calc or Draw/Impress. The internal design seems different.

I have solved the remaining problem and created extension Images Embedder. It adds a new item in menu Tools > Options to embed images in the current document. It works on Writer, Calc, Draw, Impress documents.
______
Bernard
Last edited by B Marcelly on Thu Oct 29, 2009 2:29 pm, edited 1 time in total.
z12t34
Posts: 13
Joined: Thu Oct 15, 2009 12:21 am

Re: Breaking links and emedding images into document from VB

Post by z12t34 »

Dear friend... THANKS A MILLION...

IT REALY WORKS.... I just had to shape a code a litle in order to make it work in VB6 and in my project and it works perfectly :-)

Again, thank you very much!!!!

Code: Select all

'   This code is based on code provided by Ariel Constenla-Haile, see
'   http://www.mail-archive.com/dev@api.openoffice.org/msg09255.html 

Sub embedImagesInWriter(ByRef oDoc As Object, ByRef oSM)
    On Error Resume Next '*'
    
    Dim allImages As Object, imageX As Object, oGraphicProvider As Object
    Dim x As Long
    Dim aMediaProperties(0)
    
    Set allImages = oDoc.GraphicObjects
    For x = 0 To allImages.count - 1
      Set imageX = allImages.getByIndex(x)
      If InStr(1, imageX.GraphicURL, "vnd.sun.star.GraphicObject:", 0) = 0 Then
        Set oGraphicProvider = oSM.createInstance("com.sun.star.graphic.GraphicProvider")
        Set aMediaProperties(0) = MakePropertyValue("URL", imageX.GraphicURL, oSM)
        imageX.graphic = oGraphicProvider.queryGraphic(aMediaProperties)
      End If
    Next
End Sub

Public Function MakePropertyValue(cName, uValue, ByRef oSM)
    On Error Resume Next '*'
    
    Dim oStruct
    Set oStruct = oSM.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
    oStruct.Name = cName
    oStruct.Value = uValue
    Set MakePropertyValue = oStruct
End Function
OpenOffice 3.1. on XP
Gabrielwer
Posts: 3
Joined: Fri Sep 09, 2011 3:31 pm

Re: [Solved] Breaking links and emedding images into odt fro

Post by Gabrielwer »

Thanks!
In my case I imported html document with images. This solved described problem with images in document on another machine.
BTW, in M$ Word, I wrote VB script to embed images (few years ago. it might be solved in recent version :-D )
OpenOffice 3.1 on Windows Vista / NeoOffice 2.2.3 with MacOS 10.4 / OpenOffice 2.4 on Ubuntu 9.04
Post Reply