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

Enumerating all graphical objects in order

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


Joined: 02 Jun 2009
Posts: 5

PostPosted: Sun Jun 07, 2009 10:29 pm    Post subject: Enumerating all graphical objects in order Reply with quote

I have a Word document, which I open in OOo macro and I need to enumerate all the graphical objects in the same order they are shown in the document. I can enumerate the normal pictures, but I can't find out how to access the math formulas(OLE object of some kind). I am not sure, is it because they are not normal pictures, or is it because it is inside a table.

Keep iin mind, that the order is important, so just getting all the objects with getGraphicObjects and getEmbeddedObjects is not enough. I appreciate any help, thanks!
Back to top
View user's profile Send private message
tukez
General User
General User


Joined: 02 Jun 2009
Posts: 5

PostPosted: Mon Jun 08, 2009 1:53 am    Post subject: Reply with quote

Ok I got it to work, but I have wierd problem. If I don't insert Wait statement before creating first enumeration, at least the first picture is enumerated twice. I tested this with a document with just 2 pictures and ended up with 3 pictures, first 2 being the same picture.

If I insert the Wait(or use breakpoint when debugging), everything works and I get the correct 2 pictures. Here is the code:

Code:

Sub exportGraphics(oDoc, dURL)

  dDirectory = getDirectoryPathFromURL(dURL)

  gProvider = createUnoService("com.sun.star.graphic.GraphicProvider")
  graphicCounter = 1
  Dim aArgs(1) as new com.sun.star.beans.PropertyValue
 
 'Why do I have to use Wait for this to work?
  Wait 500
 
  textEnum = oDoc.Text.createEnumeration()
         
  Do While textEnum.hasMoreElements()
    elem = textEnum.nextElement()

    if elem.supportsService("com.sun.star.text.Paragraph") then
      subEnum = elem.createEnumeration()
      Do While subEnum.hasMoreElements()
        sElem = subEnum.nextElement()
        cEnum = sElem.createContentEnumeration("")
        Do While cEnum.hasMoreElements()
          c = cEnum.nextElement()
     
          aArgs(0).Name = "URL"
          aArgs(0).Value = dDirectory + "kuva" + CStr(graphicCounter) + ".png"
          graphicCounter = graphicCounter + 1
          aArgs(1).Name = "MimeType"
          aArgs(1).Value = "image/png"
          if c.supportsService("com.sun.star.text.TextEmbeddedObject") then
            gProvider.storeGraphic(c.ReplacementGraphic, aArgs)
          endif
          if c.supportsService("com.sun.star.text.TextGraphicObject") then
            gProvider.storeGraphic(c.Graphic, aArgs)
          endif
        Loop
      Loop
    endif
           
    if elem.supportsService("com.sun.star.text.TextTable") then
      cellNames = elem.getCellNames()
      For i = LBound(cellNames) To UBound(cellNames)
        cell = elem.getCellByName(cellNames(i))
               
        cellEnum = cell.createEnumeration()
        Do While cellEnum.hasMoreElements()
          cellElem = cellEnum.nextElement()
          cellSubEnum = cellElem.createEnumeration()
          Do While cellSubEnum.hasMoreElements()
            cellSubElem = cellSubEnum.nextElement()
            cellContentEnum = cellSubElem.createContentEnumeration("")
            Do While cellContentEnum.hasMoreElements()
              c = cellContentEnum.nextElement()
                     
              aArgs(0).Name = "URL"
              aArgs(0).Value = dDirectory + "kuva" + CStr(graphicCounter) + ".png"
              graphicCounter = graphicCounter + 1
              aArgs(1).Name = "MimeType"
              aArgs(1).Value = "image/png"
              if c.supportsService("com.sun.star.text.TextEmbeddedObject") then
                gProvider.storeGraphic(c.ReplacementGraphic, aArgs)
              endif
              if c.supportsService("com.sun.star.text.TextGraphicObject") then
                gProvider.storeGraphic(c.Graphic, aArgs)
              endif
            Loop
          Loop
        Loop
      Next
    endif
  Loop
End Sub


I have a second problem: How do I crop the images? This way of exporting images loses the cropping, which is done in Word.

I'm using Open Office 3.0 on Linux.
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