openoffice-api mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Holgate <>
Subject RE: insert image into calc document
Date Thu, 08 Aug 2013 02:50:26 GMT
When you insert an image into a document using the Insert - Image - From File... function with
the user interface, there is a check box that says "Link". When you remove the check from
the check box, OpenOffice embeds the image. If you leave the check checked, then only a link
to the image is embedded. If you move or change a linked image, then the document does not
display your original image. The advantage of embedding a link over embedding a file is that
the document takes up less space. 
One way to figure out what is going on with the application is to record the action with the
Macro recorder. The code that that the Macro Recorder generates may use an inefficient programming
style, but it does give you some insight how the program processes requests and organizes
A couple of years ago, Ariel Del Valle came up with a basic extension that substituted one
image with another one resized to the same picture size. He ended up using the following method
to "break the link" so that the image was stored in the OpenOffice document rather than referring
to an external image. Although the language here is StarBasic, it uses OpenOffice objects
that are accessible in the other languages supported by OpenOffice. 
sub breakLink (byval oFirstFile,byval oGraph)	'Graphic handling based on code (c) 2011 Ariel
Del Valle	'This program is free software; you can redistribute it and/or modify	'it under
the terms of the GNU General Public License as published by	'the Free Software Foundation;
either version 2 of the License, or	'(at your option) any later version.	'	'This program is
distributed in the hope that it will be useful,	'but WITHOUT ANY WARRANTY; without even the
implied warranty of	'MERCHANTABILITY or FITNESS for A PARTICULAR PURPOSE.See the	'GNU General
Public License for more details.	'	'You should have received a copy of the GNU General Public
License	'along with this program; if not, write to the Free Software	'Foundation, Inc., 59
Temple Place, Suite 330, Boston, MA02111-1307USA	on error resume next	dim oBitmaps	oBitmaps
= ThisComponent.createInstance("") 	oBitmaps.insertByName("Image",
oFirstFile) ' we store the image in the bitmap holder    oGraph.GraphicURL = oBitmaps.getByName("Image")
' we give the image the location of the picture which is stored within the document	oBitmaps.removeByName("Image")
'once that we have given the image a picture we no longer need it inside of the oBitmapend
For some context, I use Ariel's sub to break the link when importing image files in a directory
to a impress presentation. It's in the modPhotoAlbum module in the AbilityTools extension
You can check an OpenDocument for what media it actually contains by renaming the extension
of your open document file to .zip. If you browse through the zip compressed folders, you
will find a media folder containing all the images embedded in the document. If there are
images in the folder, this will tell you if you have successfully embedded your images rather
than linking them.
I'm sorry I can't offer more help, but perhaps some of this information will give you some
clues that will help you solve your problem.
> From:
> To:;
> Subject: RE: insert image into calc document
> Date: Tue, 6 Aug 2013 21:03:47 +0300
> Sorry, but i don't know english very well and i can't express my opinion in
> an affordable manner.<неиI want to leave image in file body of calc
> document. Code that i wrote here only leaves a link to image like
> 'D:\image.jpeg'.<неиBut i want to insert image how it insert
> <неи<неиCan you help me in this
> question?<неи<неиThanks.<неи<неи-----Original Message-----<неиFrom:
> Douglas Pitonyak [] <неиSent: Tuesday, August 06,
> 2013 6:58 PM<неиTo:<неиSubject: Re: insert image
> into calc document<неи<неиInteresting question....<неи<неиWhen
you insert
> your image into the document, it then has an internal <неиURL. The question
> is.... how to remove the image from the GUI and leave <неиit in the
> file.<неи<неи<неиOn 08/05/2013 12:21 PM, K.Misha wrote:<неи>
> From: K.Misha []<неи> Sent: Monday, August 05, 2013
> 7:21 PM<неи> To: ''<неи> Subject: insert image
into calc
> document<неи><неи>   <неи><неи> Hello!<неи><неи>
  <неи><неи> I have a
> problem with inserting image into calc document!<неи><неи> I'm doing
it this
> way:<неи><неи>   <неи><неи> void insertImage( imgPosition
iPos, imgSize
> iSize, char * imgUrl )<неи><неи> {<неи><неи> Reference<
> com::sun::star::drawing::XDrawPagesSupplier ><неи>
> xDrawPagesSupplier(xCalcComponent, UNO_QUERY);<неи><неи>        Reference<
> XDrawPages > xDrawPages(<неи> xDrawPagesSupplier->getDrawPages(), UNO_QUERY
> );<неи><неи>        Reference< XDrawPage > xDrawPage(
> xDrawPages->getByIndex(irSheet),<неи> UNO_QUERY );<неи><неи>
> Reference< XShapes > xShapes(xDrawPage, UNO_QUERY);<неи><неи>
> com::sun::star::awt::Point imgPoint;<неи><неи>
> com::sun::star::awt::Size imgSize;<неи><неи>   <неи><неи>
> imgSize.Height = iSize.h;<неи><неи>        imgSize.Width =
> iSize.w;<неи><неи>      imgPoint.X = iPos.x;<неи><неи>
     imgPoint.Y =
> iPos.y;<неи><неи>        ////////the size in 100/th mm<неи><неи>
> <неи><неи>        Reference<XSpreadsheetDocument> xSheetDocument<неи>
> (xCalcComponent,UNO_QUERY);<неи><неи>      Reference< XModel >
> (xSheetDocument, UNO_QUERY);<неи><неи>
> Reference<XMultiServiceFactory> aFact(aDrawDoc,UNO_QUERY);<неи><неи>
> Reference< XShape > xShape(<неи>
> aFact->createInstance(OUString::createFromAscii("
> <неи> cObjectShape")), UNO_QUERY);<неи><неи>        //Reference<
XShape >
> xShape( xShapes->getByIndex(0), UNO_QUERY);<неи><неи>   <неи><неи>
> Reference<XPropertySet> rColProps(xShape, UNO_QUERY);<неи><неи>
> char * img = imgUrl;//"file:///D:/getImage3.jpeg";<неи><неи>      
> nLenOfWideCharStr<неи>
> =MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,img,-1,NULL,0);<неи><неи>
> wchar_t *cImg = (PWSTR)HeapAlloc(GetProcessHeap(), 0,<неи> nLenOfWideCharStr
> * sizeof(WCHAR));<неи><неи>   <неи>
> MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,img,-1,cImg,nLenOfWideCharStr);<не
> и><неи>   <неи><неи>        OUString sstring = cImg;<неи><неи>
> <неи>
> rColProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicURL
> <неи> ")), makeAny(sstring));<неи><неи>   <неи>
> //rColProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Name")),
> <неи> makeAny(sstring));<неи><неи>   <неи><неи>
> xShape->setPosition(imgPoint);<неи><неи>
> xShape->setSize(imgSize);<неи><неи>        xDrawPage->add(xShape);<неи><неи>
> }<неи><неи>   <неи><неи> //////////////////////////////////////<неи><неи>
> But every time when i open this calc document, image must be in this path
> -<неи> imgUrl. How can i insert image into file body of calc
> document?<неи><неи>   <неи><неи> Thanks!<неи><неи><неи<неи--
> Pitonyak<неиMy Macro Document:
> -----------------------------------<неиTo unsubscribe, e-mail:
><неиFor additional commands, e-mail:
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message