{
try
{
// Use the document's factory to create a new text frame and immediately access
// it's XTextFrame interface
XTextFrame xFrame = (XTextFrame) UnoRuntime.queryInterface (
XTextFrame.class, mxDocFactory.createInstance (
"com.sun.star.text.TextFrame" ) );
// Access the XShape interface of the TextFrame
XShape xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xFrame);
// Access the XPropertySet interface of the TextFrame
XPropertySet xFrameProps = (XPropertySet)UnoRuntime.queryInterface(
XPropertySet.class, xFrame );
// Set the size of the new Text Frame using the XShape's 'setSize' method
Size aSize = new Size();
aSize.Height = 400;
aSize.Width = 15000;
xShape.setSize(aSize);
// Set the AnchorType to com.sun.star.text.TextContentAnchorType.AS_CHARACTER
xFrameProps.setPropertyValue( "AnchorType", TextContentAnchorType.AS_CHARACTER );
// Go to the end of the text document
mxDocCursor.gotoEnd( false );
// Insert a new paragraph
mxDocText.insertControlCharacter (
mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false );
// Then insert the new frame
mxDocText.insertTextContent(mxDocCursor, xFrame, false);
// Access the XText interface of the text contained within the frame
XText xFrameText = xFrame.getText();
// Create a TextCursor over the frame's contents
XTextCursor xFrameCursor = xFrameText.createTextCursor();
// Insert some text into the frame
xFrameText.insertString(
xFrameCursor, "The first line in the newly created text frame.", false );