| View previous topic :: View next topic |
| Author |
Message |
satishbejgum Power User


Joined: 17 Sep 2007 Posts: 74
|
Posted: Fri Jan 11, 2008 10:44 am Post subject: [impress]how to set background image using java |
|
|
Hello Everyone
Can any any tell me how set a image as back ground for slide, it need not to be embedded in to the file
Thanks |
|
| Back to top |
|
 |
satishbejgum Power User


Joined: 17 Sep 2007 Posts: 74
|
Posted: Mon Jun 23, 2008 10:07 pm Post subject: |
|
|
| Code: | public void callinMain() {
try {
java.io.File sourceFile = new java.io.File("C:/Documents and Settings/prameelar/Desktop/wwwwwww.odp");
StringBuffer sUrl = new StringBuffer("file:///");
sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));
XComponent xComponent = loadDocument(sUrl.toString());
com.sun.star.style.XStyleFamiliesSupplier xSFS = (com.sun.star.style.XStyleFamiliesSupplier) UnoRuntime.queryInterface(com.sun.star.style.XStyleFamiliesSupplier.class, xComponent);
com.sun.star.container.XNameAccess xFamilies = xSFS.getStyleFamilies();
String[] Families = xFamilies.getElementNames();
Object aFamilyObj = xFamilies.getByName(Families[1]); //page style
com.sun.star.container.XNameAccess xStyles = (com.sun.star.container.XNameAccess) UnoRuntime.queryInterface(com.sun.star.container.XNameAccess.class, aFamilyObj);
String[] elementNames = xStyles.getElementNames();
for (int i = 0; i < elementNames.length; i++) {
String string = elementNames[i];
System.out.println(string);
if (string.equals("background")) {
XPropertySet xpro = (XPropertySet) AnyConverter.toObject(XPropertySet.class, xStyles.getByName(string));
sourceFile = new java.io.File("C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Picture1.jpg");
sUrl = new StringBuffer("file:///");
sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));
String convertedURL = getInternalURL(xComponent, sUrl.toString(), "name");
xpro.setPropertyValue("FillStyle", FillStyle.BITMAP_value);
xpro.setPropertyValue("FillBackground", new Boolean(true));
xpro.setPropertyValue("FillBitmapURL", convertedURL);
xpro.setPropertyValue("FillBitmapTile", new Boolean(false));
}
}
} catch (Exception ex) {
Logger.getLogger(Bullets.class.getName()).log(Level.SEVERE, null, ex);
}
} |
|
|
| Back to top |
|
 |
ssureshkumar Power User

Joined: 21 Dec 2005 Posts: 71
|
Posted: Wed Jun 25, 2008 4:27 am Post subject: |
|
|
Hi sathish,
Thanks for posting this code. This is useful for all.
Can you please post the code for the method
getInternalURL(xComponent, sUrl.toString(), "name");
thanks,
Suresh. |
|
| Back to top |
|
 |
satishbejgum Power User


Joined: 17 Sep 2007 Posts: 74
|
Posted: Wed Jun 25, 2008 9:25 pm Post subject: |
|
|
| Code: | public String getInternalURL(XComponent xDrawDoc, String srcUrl, String imgName) {
try {
XMultiServiceFactory xFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xDrawDoc);
Object xBitObj = xFactory.createInstance("com.sun.star.drawing.BitmapTable");
XNameContainer bitMaps = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, xBitObj);
bitMaps.insertByName(imgName, srcUrl);
return (String) bitMaps.getByName(imgName);
} catch (Exception ex) {
}
return null;
} |
|
|
| Back to top |
|
 |
ssureshkumar Power User

Joined: 21 Dec 2005 Posts: 71
|
Posted: Fri Jun 27, 2008 5:19 am Post subject: |
|
|
hi sathish,
thanks for posting the code.
but it throws com.sun.star.container.NoSuchElementException in the
line (String) bitMaps.getByName(imgName);
can you please help in this regard?
Thanks,
Suresh. |
|
| Back to top |
|
 |
satishbejgum Power User


Joined: 17 Sep 2007 Posts: 74
|
Posted: Sun Jun 29, 2008 8:43 pm Post subject: |
|
|
I think there no image to that path.
do a sample test, debug your code.
when you enter into getInternalURL method, check what is value of srcUrl.
copy that value and paste on the address bar of your browser.
i think you wont get that image. |
|
| Back to top |
|
 |
|