[Solved] Directly embed images from web inside Writer docs

Creating a macro - Writing a Script - Using the API

[Solved] Directly embed images from web inside Writer docs

Postby Tommy » Mon Jan 28, 2008 10:42 am

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:
viewtopic.php?f=7&t=2053&st=0&sk=t&sd=a&start=10
http://www.oooforum.org/forum/viewtopic ... sc&start=0
Last edited by Tommy on Sun Feb 17, 2008 5:10 pm, edited 1 time in total.
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
Tommy
 
Posts: 252
Joined: Sun Dec 23, 2007 2:44 pm

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

Postby JohnV » Tue Jan 29, 2008 2:05 am

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.
JohnV
Volunteer
 
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

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

Postby Tommy » Sat Feb 02, 2008 4:58 pm

i tried to record that sequence as a macro

Code: Select all   Expand viewCollapse view
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?
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
Tommy
 
Posts: 252
Joined: Sun Dec 23, 2007 2:44 pm

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

Postby probe1 » Fri Feb 08, 2008 10:29 pm

Andrew has multiple code examples in his free macro document
Cheers
Winfried

DateTime2 extension: insert date, time or timestamp, formatted to your needs
User avatar
probe1
Volunteer
 
Posts: 277
Joined: Mon Oct 08, 2007 1:34 am
Location: Chonburi Thailand

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

Postby Tommy » Sat Feb 09, 2008 8:50 pm

i'm analphabet with macro code. :oops:

i'd take ages to learn it... :cry:
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
Tommy
 
Posts: 252
Joined: Sun Dec 23, 2007 2:44 pm

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

Postby probe1 » Tue Feb 12, 2008 7:10 pm

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
Cheers
Winfried

DateTime2 extension: insert date, time or timestamp, formatted to your needs
User avatar
probe1
Volunteer
 
Posts: 277
Joined: Mon Oct 08, 2007 1:34 am
Location: Chonburi Thailand

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

Postby Tommy » Wed Feb 13, 2008 12:02 am

i keep my fingers crossed.

you are a macro wizard, i know you will do it!!!
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
Tommy
 
Posts: 252
Joined: Sun Dec 23, 2007 2:44 pm

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

Postby Tommy » Sun Feb 17, 2008 11:41 am

any news my friend? ;)
did u find anything useful? :D
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
Tommy
 
Posts: 252
Joined: Sun Dec 23, 2007 2:44 pm

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

Postby probe1 » Sun Feb 17, 2008 4:39 pm

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...
Cheers
Winfried

DateTime2 extension: insert date, time or timestamp, formatted to your needs
User avatar
probe1
Volunteer
 
Posts: 277
Joined: Mon Oct 08, 2007 1:34 am
Location: Chonburi Thailand

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

Postby Tommy » Sun Feb 17, 2008 5:04 pm

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
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
Tommy
 
Posts: 252
Joined: Sun Dec 23, 2007 2:44 pm

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

Postby Tommy » Mon Jun 09, 2008 6:39 am

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   Expand viewCollapse view
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
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
Tommy
 
Posts: 252
Joined: Sun Dec 23, 2007 2:44 pm

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

Postby pitonyak » Mon Jun 23, 2008 3:41 am

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   Expand viewCollapse view
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
Andrew Pitonyak
http://www.pitonyak.org/oo.php
LO and AOO on Fedora
pitonyak
Volunteer
 
Posts: 186
Joined: Sun Oct 07, 2007 9:13 pm
Location: Columbus, Ohio, USA

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

Postby Tommy » Tue Jun 24, 2008 9:53 pm

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
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
Tommy
 
Posts: 252
Joined: Sun Dec 23, 2007 2:44 pm

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

Postby Tommy » Mon Jun 30, 2008 7:54 am

*up*
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
Tommy
 
Posts: 252
Joined: Sun Dec 23, 2007 2:44 pm

Re: Directly embed images from web inside Writer docs

Postby vanhorentrash » Sat May 23, 2009 12:13 am

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
OOo 3.0.X on Ms Windows XP
vanhorentrash
 
Posts: 21
Joined: Sat Apr 11, 2009 11:57 pm

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

Postby sarath » Wed Nov 11, 2009 3:36 pm

FYI. someone might need this
An issue similar to this[solved], in java Find here
GOOO 3.1.1 on Windows XP
sarath
 
Posts: 10
Joined: Tue Oct 27, 2009 5:50 pm

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

Postby Tommy » Tue Dec 01, 2009 4:46 pm

-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
User avatar
Tommy
 
Posts: 252
Joined: Sun Dec 23, 2007 2:44 pm

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

Postby ploughansen » Tue Dec 08, 2009 3:45 pm

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?
OOo 3.1.X on Ms Windows XP + Mac OSX 10.5.7
ploughansen
 
Posts: 3
Joined: Mon Jul 27, 2009 11:20 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 7 guests