HashMap configuration = new HashMap();
configuration.put(IOfficeApplication.APPLICATION_HOME_KEY,
OPEN_OFFICE_ORG_PATH);
configuration.put(IOfficeApplication.APPLICATION_TYPE_KEY,
IOfficeApplication.LOCAL_APPLICATION);
final IOfficeApplication officeAplication = OfficeApplicationRuntime
.getApplication(configuration);
officeAplication.setConfiguration(configuration);
officeAplication.activate();
IDocumentService documentService = officeAplication.getDocumentService();
IDocument document = documentService.constructNewDocument(
IDocument.WRITER, new DocumentDescriptor());
ITextDocument textDocument = (ITextDocument) document;
boolean useStream = true;
GraphicInfo graphicInfo = null;
String imagePath = "d:\\my_image.gif";
int pixelWidth = 265;
int pixelHeight = 256;
if(!useStream) {
//with url
graphicInfo = new GraphicInfo(imagePath, pixelWidth, true, pixelHeight, true,
VertOrientation.TOP, HoriOrientation.LEFT,
TextContentAnchorType.AT_PARAGRAPH);
}
else {
//with stream
graphicInfo = new GraphicInfo(new FileInputStream(imagePath), pixelWidth,
true, pixelHeight, true, VertOrientation.TOP, HoriOrientation.LEFT,
TextContentAnchorType.AT_PARAGRAPH);
}
ITextContentService textContentService = textDocument.getTextService()
.getTextContentService();
ITextCursor textCursor = textDocument.getTextService().getText()
.getTextCursorService().getTextCursor();
ITextDocumentImage textDocumentImage = textContentService
.constructNewImage(graphicInfo);
textContentService.insertTextContent(textCursor.getEnd(),
textDocumentImage);
officeAplication.deactivate();
}
catch(OfficeApplicationException exception) {
exception.printStackTrace();
}
catch(Throwable exception) {