6

我想使用 Open Office / Libre Office 演示文稿作为模板并将文本和图像插入幻灯片。我正在尝试使用 odftoolkit。如果我有一张带框的幻灯片,它们将<draw:frame>在 XML中表示

我如何访问这些以在其中放置图像?我应该使用这些课程吗?

  • org.odftoolkit.simple.PresentationDocument
  • org.odftoolkit.simple.presentation.Slide

当我打开幻灯片时,我看到的相关方法是:

  • .getOdfElement
  • .getFrameContainerElement

但我看不到如何在幻灯片中选择框架。当我打开 XML 时,我在<draw:page>.

具有如下属性:presentation:style-name="pr2" draw:layer="layout"

4

1 回答 1

4

正如尤金所说,我必须找到目标框架并做更多的工作。没有将图像添加到框架的方法,只能添加到幻灯片中。我进入了方法并成功如下:

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 的东西,因为我认为我错过了一些样式和更好的查找框架的方法。但无论如何,这还不错。

于 2014-03-05T16:08:01.123 回答