How to change position of text shape in OpenOffice API for Java?

301 Views Asked by At

I'm try to use Nice Office Access (NOA) to embbed OpenOffice Writer to my OCR program. I can add text shape to document see code below, but I don't know how to change its position. Someone help me!

try {
    // Init office
    HashMap configuration = new HashMap();
    configuration.put(IOfficeApplication.APPLICATION_HOME_KEY, OPEN_OFFICE_ORG_PATH);
    configuration.put(IOfficeApplication.APPLICATION_TYPE_KEY, IOfficeApplication.LOCAL_APPLICATION);
    officeAplication = OfficeApplicationRuntime.getApplication(configuration);
    officeAplication.setConfiguration(configuration);
    officeAplication.activate();

    // Init frame and get service
    IFrame officeFrame = officeAplication.getDesktopService().constructNewOfficeFrame(panRight);
    IDocumentService documentService = officeAplication.getDocumentService();
    ITextDocument textDocument = (ITextDocument) documentService.constructNewDocument(officeFrame, IDocument.WRITER, DocumentDescriptor.DEFAULT);
    ITextService textService = textDocument.getTextService();
    ITextContentService textContentService = textService.getTextContentService();
    IText text = textService.getText();
    ITextCursorService textCursorService = text.getTextCursorService();
    ITextCursor textCursor = textCursorService.getTextCursor();

    // Insert text shape
    TextInfo textInfo = new TextInfo("Hello", VertOrientation.TOP, HoriOrientation.LEFT, 100, true, true, 100, true, true, 0xFFFFFF, TextContentAnchorType.AT_PAGE);
    ITextDocumentTextShape textDocumentTextShape = textContentService.constructNewTextShape(textInfo);
    textContentService.insertTextContent(textDocumentTextShape);

    XText xText = textDocumentTextShape.getXText();
    XTextRange xTextRange = xText.createTextCursor();
    XPropertySet xTextProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextRange);

    xTextProps.setPropertyValue("CharFontName", "Courier New");
    xTextProps.setPropertyValue("CharWeight", new Float(FontWeight.BOLD));
    xTextProps.setPropertyValue("CharPosture", FontSlant.ITALIC);
    xTextProps.setPropertyValue("CharHeight", new Float(28));
    xText.insertString(xText.getEnd(), "My First OpenOffice Document", true);

    // Now it is time to disable two commands in the frame
    officeFrame.disableDispatch(GlobalCommands.CLOSE_DOCUMENT);
    officeFrame.disableDispatch(GlobalCommands.QUIT_APPLICATION);
    officeFrame.updateDispatches();
} catch (Throwable throwable) {
    throwable.printStackTrace();
}
1

There are 1 best solutions below

0
On
xTextProps1.setPropertyValue("HoriOrient", HoriOrientation.NONE);
xTextProps1.setPropertyValue("HoriOrientRelation", RelOrientation.PAGE_FRAME);
xTextProps1.setPropertyValue("HoriOrientPosition", <X position>);

xTextProps1.setPropertyValue("VertOrient", VertOrientation.NONE);
xTextProps1.setPropertyValue("VertOrientRelation", RelOrientation.PAGE_FRAME);
xTextProps1.setPropertyValue("VertOrientPosition", <Y position>);