open office version 4.1.6 . issues which we are facing is in many of the templates we have used bookmarks those will hold the images passed at runtime.
but we observed that images are sometimes comming on in the pdf and sometimes they are not comming . can you please provide some idea why this issue
can be occurred
below is the sample code written for the same
Code: Select all
public void placeImage(XComponent aDoc, String szImageURL_1,String szImageURL_2, int lHeight, int lWidth) throws java.lang.Exception
{
OOCommonUtils.logMessage("Entry:OOImageProcessing:placeImage()");
try{
XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, aDoc);
XBookmarksSupplier xBookmarksSupplier = (XBookmarksSupplier) UnoRuntime.queryInterface(XBookmarksSupplier.class, xTextDocument);
XNameAccess xNamedBookmarks = xBookmarksSupplier.getBookmarks();
String [] szArrBookmarkNames =new String[2];
szArrBookmarkNames= xNamedBookmarks.getElementNames();
Object objBookMarks=null;
String[] szImageURL=new String[]{szImageURL_1,szImageURL_2};
if (szArrBookmarkNames!=null && szImageURL_1 !=null && szImageURL_2 !=null )
{
for(int i=0;i<szArrBookmarkNames.length;i++)
{
objBookMarks = xNamedBookmarks.getByName(szArrBookmarkNames[i]);
XTextContent xBookmarkContent = (XTextContent)UnoRuntime.queryInterface(XTextContent.class,objBookMarks );
XMultiServiceFactory mxDocFactory = (XMultiServiceFactory)
UnoRuntime.queryInterface( XMultiServiceFactory.class, xTextDocument );
Object oGraphicObject = mxDocFactory.createInstance("com.sun.star.text.GraphicObject");
XTextContent xGraphicContent = (XTextContent)UnoRuntime.queryInterface(
XTextContent.class, oGraphicObject);
XPropertySet xGraphicProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xGraphicContent );
xGraphicProps.setPropertyValue("AnchorType", TextContentAnchorType.AT_CHARACTER);
xGraphicProps.setPropertyValue("BackTransparent", new Boolean(true));
com.sun.star.awt.Size aSize = new com.sun.star.awt.Size();
aSize.Height = lHeight;
aSize.Width = lWidth;
xGraphicProps.setPropertyValue("Size", aSize);
xGraphicProps.setPropertyValue("GraphicURL","file:///"+szImageURL[i] );
XTextRange xBookmarkRange = xBookmarkContent.getAnchor();
XText xText = xBookmarkRange.getText();
XTextCursor curText = xText.createTextCursor();
xText.insertTextContent(xBookmarkRange, xGraphicContent, false);
xBookmarkContent = null;
xGraphicContent = null;
xGraphicProps = null;
oGraphicObject = null;
xBookmarkRange = null;
xText = null;
//curText = null;
}
}
}
catch(java.lang.Exception e)
{
OOCommonUtils.logError("Exception:OOImageProcessing:placeImage()"+e);
OOCommonUtils.traceException(e);
throw e;
}
OOCommonUtils.logMessage("Exit:OOImageProcessing:placeImage()");
}