Page 1 of 1

[Solved] Directly embed images from web inside Writer docs

Posted: Mon Jan 28, 2008 10:42 am
by Tommy
copying & pasting images from webpages into OOo Writes docs is not as easy as in MS Word.
MS Word directly embeds images in the document while OOo has a different behaviour and embedding must be done manually.
You have to paste the text and images into a text document, then use the Edit > Links box to break links to the images to embed them in the document.
this manual method is not very user friendly (expecially fo newbies) and is time consuming if you have multiple pictures to embed.
i'd like to have a macro o extension that can directly embed images in witer documents after capy&paste from web.
unfortunately i have no skills to code such a macro, so i wonder if one of the macro experts of this forum can do it.
thank you. ;)


Related topics:
http://user.services.openoffice.org/en/ ... a&start=10
http://www.oooforum.org/forum/viewtopic ... sc&start=0

Re: [REQ] directly embed images from web inside Writer docs

Posted: Tue Jan 29, 2008 2:05 am
by JohnV
No macro help but if you have a lot of images just select them all before click "Break Link". The first will be selected, just Shift + click on the last. Try it with a copy of this thread.

Re: [REQ] directly embed images from web inside Writer docs

Posted: Sat Feb 02, 2008 4:58 pm
by Tommy
i tried to record that sequence as a macro

Code: Select all

sub BreakImageLinks
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SelectAll", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:LinkDialog", "", 0, Array())


end sub
the only thing is that the Shift + click has to be done manually.

is there any macro guru that can edit my code and automatize this last step as well?

Re: [REQ] directly embed images from web inside Writer docs

Posted: Fri Feb 08, 2008 10:29 pm
by probe1
Andrew has multiple code examples in his free macro document

Re: [REQ] directly embed images from web inside Writer docs

Posted: Sat Feb 09, 2008 8:50 pm
by Tommy
i'm analphabet with macro code. :oops:

i'd take ages to learn it... :cry:

Re: [REQ] directly embed images from web inside Writer docs

Posted: Tue Feb 12, 2008 7:10 pm
by probe1
I think i saw working macro code in another forum today - but have no time to search for it now (and test it) .... maybe later this night - stay tuned

Re: [REQ] directly embed images from web inside Writer docs

Posted: Wed Feb 13, 2008 12:02 am
by Tommy
i keep my fingers crossed.

you are a macro wizard, i know you will do it!!!

Re: [REQ] directly embed images from web inside Writer docs

Posted: Sun Feb 17, 2008 11:41 am
by Tommy
any news my friend? ;)
did u find anything useful? :D

Re: [REQ] directly embed images from web inside Writer docs

Posted: Sun Feb 17, 2008 4:39 pm
by probe1
Had a deeper look - and don't see an easy way.

Problem is, that loading the image from web with code times out.

So you will manually have to download the images (with same name as link, preferable). Adopting Andrew's macro should be a work of diligence - not for me in near future...

Re: [REQ] directly embed images from web inside Writer docs

Posted: Sun Feb 17, 2008 5:04 pm
by Tommy
ok, nevermind.

my macro does much of the work.
only few click are required for the user and is not that time consuming.

if the "Ctrl-Shift selection and break links command" thing cannot be automized is not so important.

i will put a [solved] tag to the topic.
however, if anybody will find how to code a better macro than mine, please post it here!!! :D

Re: [solved] directly embed images from web inside Writer docs

Posted: Mon Jun 09, 2008 6:39 am
by Tommy
i found a better macro that does all the job with just one click.

credits to pablo from the italian OOo Google Discussion Group
http://groups.google.it/group/it-alt.co ... b8074f73d2

Code: Select all

Sub EmbedGraphics() 
 oDPage = ThisComponent.DrawPage 
 oProvider = createUnoService("com.sun.star.graphic.GraphicProvider") 
 Dim oProps(0) as new com.sun.star.beans.PropertyValue 
 oProps(0).Name  = "URL" 
  If oDPage.hasElements() Then 
   For I = 0 To oDPage.Count - 1 
    oGraph = oDPage.getByIndex(I) 
    If oGraph.supportsService("com.sun.star.text.TextGraphicObject") Then 
     oProps(0).Value = oGraph.GraphicUrl 
     oGraph.Graphic = oProvider.queryGraphic(oProps()) 
    End If 
   Next I 
 End If 
End Sub

Re: [Solved] Directly embed images from web inside Writer docs

Posted: Mon Jun 23, 2008 3:41 am
by pitonyak
The previous post converts one type of image. From my free macro document, we have the following, which converts GraphicObjectShape and TextGraphicObject.

Code: Select all

Sub ConvertAllLinkedGraphics(Optional aDoc)
  Dim oDoc        ' Working document
  Dim oDP         ' Draw page
  Dim i%          ' Index counter
  Dim oGraph      ' Graph object in the draw page
  Dim iLinked%    ' Number of linked graphics
  Dim iEmbedded%  ' Number of embedded graphics
  Dim iConverted% ' Linked graphics converted to embedded
  Dim s1$         ' Graphic service name
  Dim s2$         ' Graphic service name

  REM Only know how to convert these types
  s1 = "com.sun.star.drawing.GraphicObjectShape"
  s2 = "com.sun.star.text.TextGraphicObject"

  If IsMissing(aDoc) OR IsNull(aDoc) OR IsEmpty(aDoc) Then
    oDoc = ThisComponent
  Else
    oDoc = aDoc
  End If

  REM Get the document draw page and then enumerate the graphics.
  oDP = oDoc.getDrawPage()
  For i=0 To oDP.getCount()-1
    oGraph = oDP.getByIndex(i)
    If oGraph.supportsService(s1) OR oGraph.supportsService(s2) Then
      If InStr(oGraph.GraphicURL, "vnd.sun") <> 0 Then
        iEmbedded = iEmbedded + 1
      Else
        iLinked = iLinked + 1
        If EmbedLinkedGraphic(oGraph, oDoc) Then
          iConverted = iConverted + 1
        End If
      End If
    End If
  Next
  Print "Found " & iLinked & " linked and " & iEmbedded & _
        " embedded graphics and converted " & iConverted
End Sub

Function EmbedLinkedGraphic(oGraph, oDoc) As Boolean
  REM Author: Andrew Pitonyak
  Dim sGraphURL$  ' External URL of the graphic.
  Dim oGraph_2    ' Created graphic.
  Dim oCurs       ' Cursor where the graphic is located.
  Dim oText       ' Text object containing graphic.
  Dim oAnchor     ' Anchor point of the image
  Dim s1$         ' Graphic service name
  Dim s2$         ' Graphic service name

  EmbedLinkedGraphic = False
  If InStr(oGraph.GraphicURL, "vnd.sun") <> 0 Then
    REM Ignore an image that is already embedded
    Exit Function
  End If
  s1 = "com.sun.star.drawing.GraphicObjectShape"
  s2 = "com.sun.star.text.TextGraphicObject"
  If oGraph.supportsService(s1) Then

    REM Convert a GraphicObjectShape.
    oAnchor = oGraph.getAnchor()
    oText = oAnchor.getText()
  
    oGraph_2 = ThisComponent.createInstance(s)
    oGraph_2.GraphicObjectFillBitmap = oGraph.GraphicObjectFillBitmap
    oGraph_2.Size = oGraph.Size
    oGraph_2.Position = oGraph.Position
    oText.insertTextContent(oAnchor, oGraph_2, False)
    oText.removeTextContent(oGraph)
    EmbedLinkedGraphic = True
    
  ElseIf oGraph.supportsService(s2) Then
  
    REM Convert a TextGraphicObject.
    Dim oBitmaps
    Dim sNewURL$
    Dim sName$

    sName$ = oGraph.LinkDisplayName
    oBitmaps = oDoc.createInstance( "com.sun.star.drawing.BitmapTable" )
    If oBitMaps.hasByName(sName) Then
      Print "Link display name " & sName & " already exists"
      Exit Function
    End If
    'Print "Ready to insert " & sName
    oBitmaps.insertByName( sName, oGraph.GraphicURL )
    sNewURL$ = oBitmaps.getByName( sName )
    'Print "inserted URL " & sNewURL
    oGraph.GraphicURL = sNewURL
    EmbedLinkedGraphic = True
  End If
End Function 

Re: [Solved] Directly embed images from web inside Writer docs

Posted: Tue Jun 24, 2008 9:53 pm
by Tommy
sorry i did not understand which is the difference from your macro and the one i posted above. :roll:

could you try to expain it again?

thanks

Re: [Solved] Directly embed images from web inside Writer docs

Posted: Mon Jun 30, 2008 7:54 am
by Tommy
*up*

Re: Directly embed images from web inside Writer docs

Posted: Sat May 23, 2009 12:13 am
by vanhorentrash
In Writer Macro's I've pasted the last macro published here. I really don't know how to work macro's, and so I don't know where to put my link...

I know it's stupid, but please help me from the start...So I open a blanc Writer Doc, and want to embed for example www.google.com.

What do I do?

Thanks,

Anton van Horen

Re: [Solved] Directly embed images from web inside Writer docs

Posted: Wed Nov 11, 2009 3:36 pm
by sarath
FYI. someone might need this
An issue similar to this[solved], in java Find here

Re: [Solved] Directly embed images from web inside Writer docs

Posted: Tue Dec 01, 2009 4:46 pm
by Tommy

Re: [Solved] Directly embed images from web inside Writer docs

Posted: Tue Dec 08, 2009 3:45 pm
by ploughansen
The method of breaking the links, doesn't seem to work for me.

When I do it, the images just say "Read error", and noting is displayed.

Have anyone else had this error? And does someone know how to fix it?