我找到了解決方案。當意識到我添加的所有圖像都只是圖像鏈接時,我意識到如何去做。所以我不得不嵌入圖像。
要使用此,你需要:
- 訪問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