Insert an image at the bookmark position

Java, C++, C#, Delphi, ??? - Using the UNO bridges

Insert an image at the bookmark position

Postby nassim1987 » Mon Oct 19, 2015 5:55 pm

Hello,

I develop a c++ project tha mange a OpenOffice writer documents. I want to insert an image in the bookmark position. For this I used the following program:

Code: Select all   Expand viewCollapse view
void insertImage(std::string bookmarkName,std::string fileName)
{
   Any bookmark;
   Reference< XText > xText = this->xTextDocument->getText();
   Reference< XBookmarksSupplier > xBookmarksSupplier (this->rDocument, UNO_QUERY);
   Reference< XNameAccess > rNameAccess = xBookmarksSupplier->getBookmarks();
   bookmark = rNameAccess->getByName(OUString::createFromAscii((char*)bookmarkName.c_str()));

   Reference< XTextContent >xTextContentBookmark (bookmark,UNO_QUERY);
   Reference< XTextRange >  xTextRange = xTextContentBookmark->getAnchor();
   
   // Generate a File URL
   OUString GraphicURL;
   osl::FileBase::getFileURLFromSystemPath(OUString::createFromAscii((char*)fileName.c_str()),GraphicURL);

   Reference<XMultiServiceFactory> rMSF (xTextDocument,UNO_QUERY);
   Reference <XPropertySet> rGraphic ( rMSF->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.GraphicObject" ))), UNO_QUERY );

   rGraphic->setPropertyValue(OUString::createFromAscii("GraphicURL"),makeAny(GraphicURL));
   rGraphic->setPropertyValue( OUString::createFromAscii("Width"), Any((sal_Int32 ) 1500 ) );
       rGraphic->setPropertyValue( OUString::createFromAscii("Height"), Any((sal_Int32 ) 1500 ) );

   Reference <XTextContent> xTextContent (rGraphic,UNO_QUERY);
       xText->insertTextContent(xTextRange, xTextContent,false);

}



This function put the image in the center of the line although my bookmark is in the begining of the line. In some case of my project, i have to place three image in the same line. I need for this three bookmarks and I want to put each image at the position of the appropriate bookmark. The problem all the images are placed in the center and superposed one each other.

I want to know please il there is a solution for this problem or if there is something to add to the function

Thank you.
OpenOffice 4.1.1 on Windows 7
nassim1987
 
Posts: 9
Joined: Mon Oct 19, 2015 5:15 pm

Re: insert an image at the bookmark position

Postby RoryOF » Mon Oct 19, 2015 6:03 pm

There is an existing extension to put markers at the bookmark positions.
Visible Bookmarks

I do not know if this will run on OO 4.1.1, but if you are working with macros you should be able to sort that out and to note the mechanism used to insert the marker at the correct location. Substituting the image(s) you require for the markers should be trivial.
Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28737
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: insert an image at the bookmark position

Postby nassim1987 » Mon Oct 19, 2015 6:23 pm

Thank you, but i don't thinhk that this extension is intended for c++ program.
OpenOffice 4.1.1 on Windows 7
nassim1987
 
Posts: 9
Joined: Mon Oct 19, 2015 5:15 pm

Re: insert an image at the bookmark position

Postby RoryOF » Mon Oct 19, 2015 6:26 pm

Look at the code and follow the logic. Then adapt that to C++.
Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28737
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland


Return to External Programs

Who is online

Users browsing this forum: No registered users and 1 guest