Seite 1 von 1

Verknüpfungen lösen per API (break links per API)

Verfasst: Di, 07.04.2009 18:36
von professor_
Hallo,

wenn man ein Textdokument mit verknüpften Bildern hat, kann man ja "Edit => Links => Break Links" (hab nur die engl. Version, müsste sowas wie "Verknüpfungen lösen" sein) wählen, um aus verlinkten Bildern eingebettete Bilder zu machen.

Kann man das auch per API, also durch ein externes Programm? Ich denke an so etwas wie:

Code: Alles auswählen

XTextDocument mxDocument;
...
XText xt = mxDocument.getText();
xt.BreakLinks(); // das hier meine ich - gibt es so nicht - aber vielleicht gibt es das was ich meine
Danke für Eure Hilfe!
Sabine Lorentz

Re: Verknüpfungen lösen per API (break links per API)

Verfasst: Mi, 06.05.2009 16:22
von Martin_
Hallo professor_,

meinst Du folgendes:

Code: Alles auswählen

Function breakAllGraphicLinks(aDokument as Object)
   Dim grafiken as Object
   Dim grafik as Object
   Dim i as Integer

   Dim xBitmapContainer as Object 
   Dim xImage as Object 
   Dim internalURL as String
   Dim xTextCur as Object 
   Dim xText as Object 

   grafiken = aDokument.getGraphicObjects()
   xTextCur = aDokument.text.createtextcursor()
   
   xBitmapContainer = aDokument.createInstance("com.sun.star.drawing.BitmapTable")
   For i = 0 to grafiken.count - 1
      grafik = grafiken.getByIndex(i)
      if InStr(1, grafik.GraphicURL, "vnd.sun.star.GraphicObject:", 0) = 0 then 
                xTextCur.gotoRange(grafik.anchor, false)
                xText = xTextCur.text
                xImage = aDokument.createInstance("com.sun.star.text.TextGraphicObject")

                '// helper-stuff to let OOo create an internal name of the graphic
                '// that can be used later (internal name consists of various checksums)
                xBitmapContainer.insertByName("someID", grafik.GraphicURL)
                internalURL = xBitmapContainer.getByName("someID")

                xImage.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH
                xImage.GraphicURL = internalURL
                xImage.Width = grafik.width
                xImage.Height = grafik.height
                xImage.HoriOrientPosition = grafik.HoriOrientPosition 
                xImage.VertOrientPosition = grafik.VertOrientPosition 
                '// inser the graphic at the cursor position
                xText.insertTextContent(xTextCur, xImage, false)

                '// remove the helper-entry
                xBitmapContainer.removeByName("someID")
                grafik.dispose
      end if 
   next i
   
end function
frei nach http://codesnippets.services.openoffice ... ument.snip

Gruß
Martin