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
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);
}
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.