我找到了解决方案。当意识到我添加的所有图像都只是图像链接时,我意识到如何去做。所以我不得不嵌入图像。
要使用此,你需要:
- 访问XComponentContext
- 一个TextGraphicObject文档中(见上面的链接)
- 的图像作为字节[],或使用其他流
代码:
Object graphicProviderObject = xComponentContext.getServiceManager().createInstanceWithContext(
"com.sun.star.graphic.GraphicProvider",
xComponentContext);
XGraphicProvider xGraphicProvider = UnoRuntime.queryInterface(
XGraphicProvider.class, graphicProviderObject);
PropertyValue[] v = new PropertyValue[1];
v[0] = new PropertyValue();
v[0].Name = "InputStream";
v[0].Value = new ByteArrayToXInputStreamAdapter(imageAsByteArray);
XGraphic graphic = xGraphicProvider.queryGraphic(v);
if (graphic == null) {
LOGGER.error("Error loading the image");
return;
}
XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, textGraphicObject);
// Set the image
xProps.setPropertyValue("Graphic", graphic);
即使对于我的svg图像,这也毫不费力。
来源:https://blog.oio.de/2010/05/14/embed-an-image-into-an-openoffice-org-writer-document/
来源
2017-12-20 10:11:33
Ben