我希望使用Office / Libre Office演示文稿作为模板,并将文本和图像插入幻灯片中。我正在尝试使用odftoolkit。如果我有带框的幻灯片,则它们在XML中表示为<draw:frame>。
我如何访问这些文件以在其中放置图像?我应该用这些课吗?
org.odftoolkit.simple.PresentationDocumentorg.odftoolkit.simple.presentation.Slide当我打开幻灯片时,我看到的相关方法如下:
.getOdfElement.getFrameContainerElement但是我看不出如何在幻灯片中选择框架。当我打开XML时,<draw:page>下面有5帧。
类似于:presentation:style-name="pr2" draw:layer="layout"的have属性
发布于 2014-03-05 16:08:01
正如尤金评论的那样,我必须找到目标框架,做更多的工作。没有向框架添加图像的方法,只向幻灯片添加图像。我研究了这些方法,并取得了如下成功:
DrawPageElement drawPageElement = slide.getOdfElement();
DrawFrameElement drawFrame = OdfElement.findFirstChildNode(DrawFrameElement.class, drawPageElement);
DrawImageElement image = drawFrame.newDrawImageElement();
OdfPackage mOdfPackage = odp.getPackage();
String imageRef = "/some/path/to/chart.png";
String packagePath = odp.getDocumentPath() + OdfPackage.OdfFile.IMAGE_DIRECTORY.getPath() + "/" + someMethodToCreateRandomString();
mOdfPackage.insert(new URI(imageRef), packagePath, OdfFileEntry.getMediaTypeString(imageRef));
packagePath = packagePath.replaceFirst(odp.getDocumentPath(), "");
URI uri = new URI(AnyURI.encodePath(packagePath).toString());
image.setXlinkHrefAttribute(AnyURI.decodePath(uri.toString()));
image.setXlinkActuateAttribute("onLoad");
image.setXlinkShowAttribute("embed");
image.setXlinkTypeAttribute("simple");我希望能找到更接近GUI的东西,因为我想我错过了一些样式和找到框架的更好方法。但不管怎样,这并不坏。
https://stackoverflow.com/questions/22102579
复制相似问题