我正在尝试使用java程序控制simpress演示文稿。我可以得到我的演示文稿的下一个效果,但只有当它不是全屏时。如果我将我的PropertyValue“IsFullScreen”设置为“TRUE”,我的presentation.isRunning()将返回false,并且我的xSlideShowController为null。
public static void lancerPresentation(String url) throws IndexOutOfBoundsException, com.sun.star.io.IOException, InterruptedException{
//We open the file "~/Documents/testUno.odp"
XComponent xComponent=null;
XPresentation2 presentation2 =null;
try {
// get the remote office component context
XComponentContext xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
xComponent = openPresentation(xContext, url);
XPresentationSupplier presentationSupplier = UnoRuntime.queryInterface(XPresentationSupplier.class, xComponent);
XPresentation presentation = presentationSupplier.getPresentation();
presentation2 = UnoRuntime.queryInterface(XPresentation2.class, presentation);
PropertyValue[] aPresentationArgs = new PropertyValue[3];
aPresentationArgs[0] = new PropertyValue();
aPresentationArgs[0].Name = "IsAlwaysOnTop";
aPresentationArgs[0].Value = Boolean.TRUE;
aPresentationArgs[1] = new PropertyValue();
aPresentationArgs[1].Name = "IsFullScreen";
aPresentationArgs[1].Value = Boolean.TRUE;
aPresentationArgs[2] = new PropertyValue();
aPresentationArgs[2].Name = "IsAutomatic";
aPresentationArgs[2].Value = Boolean.TRUE;
presentation2.startWithArguments(aPresentationArgs);
System.out.println(presentation2.isRunning()); ==> False
if(presentation2==null)System.out.println("presentation2 null");
}
catch( Exception e) {
e.printStackTrace(System.err);
System.exit(1);
}
if (presentation2.isRunning()) {
xSlideShowController = presentation2.getController();
if(xSlideShowController==null)System.out.println("xSlideShowController null"); ==> Null
}
我想在下一张幻灯片中保存一个文件。我试过这个,但我的XStorable是空的。
xSlideShowController.gotoFirstSlide();
XDrawPage slidePreview = xSlideShowController.getSlideByIndex(xSlideShowController.getCurrentSlideIndex()+1);
if(slidePreview==null)System.out.println("slidePreview null");
String filePath = "home/bastien/Documents/slideshowtest.jpg";
PropertyValue[] aStoreProperties = new PropertyValue[2];
aStoreProperties[0] = new PropertyValue();
aStoreProperties[1] = new PropertyValue();
aStoreProperties[0].Name = "Override";
aStoreProperties[0].Value = true;
aStoreProperties[1].Name = "FilterName";
aStoreProperties[1].Value = "slideshowtest";
XComponent previewComponent =UnoRuntime.queryInterface(
XComponent.class, slidePreview);
if(previewComponent==null)System.out.println("previewComponent null");
XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
XStorable.class, previewComponent);
if(xStorable==null)System.out.println("xStorable null"); ==> Null
xStorable.storeAsURL(filePath, aStoreProperties);
我试过了,但XStorable也是空的。
XStorable xStorable = (XStorable)
UnoRuntime.queryInterface(XStorable.class, slidePreview);
由于
答案 0 :(得分:0)
好的,我发现如何将下一张幻灯片保存为图片:
public static boolean save(String fileName) throws IndexOutOfBoundsException, IOException, com.sun.star.uno.Exception {
if(xSlideShowController.getCurrentSlideIndex() + 1>xSlideShowController.getSlideCount())return false;
XDrawPage slidePreview = xSlideShowController.getSlideByIndex(xSlideShowController.getCurrentSlideIndex() + 1);
java.io.File sourceFile = new java.io.File(fileName);
if(sourceFile.createNewFile())return false;
StringBuffer sTemplateFileUrl = new StringBuffer("file:///");
sTemplateFileUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));
PropertyValue aFilterData_thumb[] = new PropertyValue[2];
aFilterData_thumb[0] = new PropertyValue();
aFilterData_thumb[0].Name = "PixelWidth";
aFilterData_thumb[0].Value = 1241;
aFilterData_thumb[1] = new PropertyValue();
aFilterData_thumb[1].Name = "PixelHeight";
aFilterData_thumb[1].Value = 1753;
PropertyValue aProps_thumb[] = new PropertyValue[3];
aProps_thumb[0] = new PropertyValue();
aProps_thumb[0].Name = "MediaType";
aProps_thumb[0].Value = "image/jpeg";
aProps_thumb[1] = new PropertyValue();
aProps_thumb[1].Name = "URL";
aProps_thumb[1].Value = sTemplateFileUrl.toString();
aProps_thumb[2] = new PropertyValue();
aProps_thumb[2].Name = "FilterData";
aProps_thumb[2].Value = aFilterData_thumb;
XComponent xComp = UnoRuntime.queryInterface(XComponent.class, slidePreview);
XMultiComponentFactory xMCF
= xContext.getServiceManager();
Object exportFilter = xMCF.createInstanceWithContext("com.sun.star.drawing.GraphicExportFilter", xContext);
XExporter xExporter = UnoRuntime.queryInterface(XExporter.class, exportFilter);
xExporter.setSourceDocument(xComp);
XFilter xFilter = UnoRuntime.queryInterface(XFilter.class, xExporter);
xFilter.filter(aProps_thumb);
return true;
}