| View previous topic :: View next topic |
| Author |
Message |
groverblue General User

Joined: 13 Jul 2007 Posts: 48
|
Posted: Tue Mar 03, 2009 11:17 am Post subject: [SOLVED] Example of inserting a section? |
|
|
I think I've pieced together what needs to be done, but I'm still trying to figure out how to insert the entire contents of a document into a new section. I believe everything else if correct. Does anyone have any input?
| Code: |
public void appendDocument(XTextDocument document2)
throws IllegalArgumentException, java.lang.Exception {
XText xDocText = this.document.getText();
XTextCursor xOrigDocTextCursor = xDocText.createTextCursor();
XNamed xChildNamed;
XTextContent xChildSection;
XPropertySet xOrigDocTextCursorProp;
xOrigDocTextCursor.gotoEnd(false);
xDocText.insertControlCharacter(xOrigDocTextCursor, ControlCharacter.PARAGRAPH_BREAK, false);
xOrigDocTextCursorProp = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class,
xOrigDocTextCursor);
xOrigDocTextCursorProp.setPropertyValue("BreakType", BreakType.PAGE_BEFORE);
XComponentContext xRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
XMultiComponentFactory xRemoteServiceManager = xRemoteContext.getServiceManager();
xChildNamed = (XNamed) UnoRuntime.queryInterface(
XNamed.class,
xRemoteServiceManager.createInstanceWithContext("com.sun.star.text.TextSection",xRemoteContext));
xChildNamed.setName("NewSection");
xChildSection = (XTextContent) UnoRuntime.queryInterface(
XTextContent.class,
xChildNamed);
/* Add code here to insert document2 into new section */
xDocText.insertTextContent(xOrigDocTextCursor, xChildSection, false);
} |
Last edited by groverblue on Thu Mar 05, 2009 8:06 am; edited 1 time in total |
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Tue Mar 03, 2009 2:12 pm Post subject: |
|
|
| are you aware of insertDocumentFromUrl ? |
|
| Back to top |
|
 |
groverblue General User

Joined: 13 Jul 2007 Posts: 48
|
Posted: Tue Mar 03, 2009 2:45 pm Post subject: |
|
|
I just discovered it today, though I can't find any example that lets me load from an existing XTextDocument object.
I did notice the usage of "private:stream" instead of loading from the filesystem, but I can't determine from the documentation if/how an XInputStream (something else I discovered today) could be had from a XTextDocument object.
I'd like to avoid writing out files. |
|
| Back to top |
|
 |
groverblue General User

Joined: 13 Jul 2007 Posts: 48
|
Posted: Wed Mar 04, 2009 2:18 pm Post subject: |
|
|
I got everything to work, except for images and horizontal line objects. Images are completely ignored and not imported into the document, whereas horizontal line objects are flushing themselves at the top of the current page.
I do have a question about the section I am using. If you look at the following code, am I properly inserting the second document (document2) into the newly created section?
Here is my routine:
| Code: |
public void appendDocument(XTextDocument document1, XTextDocument document2)
throws IllegalArgumentException, java.lang.Exception {
XText xDocText = document1.getText();
XTextCursor xOrigDocTextCursor = xDocText.createTextCursor();
XNamed xChildNamed;
XTextContent xChildContent;
String tempDoc = generateTempDocucmentPathName();
xOrigDocTextCursor.gotoEnd(false);
xDocText.insertControlCharacter(xOrigDocTextCursor, ControlCharacter.PARAGRAPH_BREAK, false);
xChildNamed = (XNamed) UnoRuntime.queryInterface(
XNamed.class,
serviceFactory.createInstance("com.sun.star.text.TextSection", document1));
xChildNamed.setName("" + document2.hashCode());
xChildContent = (XTextContent) UnoRuntime.queryInterface(
XTextContent.class,
xChildNamed);
/* Add document2 to the new section */
xDocText.insertTextContent(xOrigDocTextCursor, xChildContent, false);
PropertyValue[] storeProps = createPropertyValueArray(
createPropertyValue("FilterName", new Any(Type.STRING, "writer8_template")),
createPropertyValue("CompressionMode", new Any(Type.STRING, "1")),
createPropertyValue("Pages", new Any(Type.STRING, "All")),
createPropertyValue("Overwrite", new Any(Type.BOOLEAN, Boolean.TRUE)));
componentExport(document2, storeProps, tempDoc);
XDocumentInsertable xDocI = (XDocumentInsertable) UnoRuntime.queryInterface(
XDocumentInsertable.class,
xOrigDocTextCursor);
PropertyValue[] loadProps=new PropertyValue[0];
xDocI.insertDocumentFromURL("file:///" + tempDoc, loadProps);
deleteFile(tempDoc);
} |
|
|
| Back to top |
|
 |
groverblue General User

Joined: 13 Jul 2007 Posts: 48
|
Posted: Thu Mar 05, 2009 8:06 am Post subject: |
|
|
I would like to let everyone know that this issue has been resolved. The original file was a Word document that we ran through a converter. Apparently, the original image was a BMP, and the conversion saved that image as an object in the ODT file (instead of an embedded image). I deleted the BMP image object from the OpenOffice template and re-added it as a PNG. Since doing so everything is working fine.
ms77, I want to thank you for your help, and I hope this thread proves useful to someone else. |
|
| Back to top |
|
 |
amohammad Newbie

Joined: 10 Sep 2012 Posts: 3
|
Posted: Mon Sep 10, 2012 6:12 am Post subject: Question regarding SECTION insertion CODE |
|
|
Hi groverblue,
I have read your post regarding SECTION insertion in document. I have problem while executing your code. I am not able to resolve the object "serviceFactory", can you please tell me what type of this object is and how to get it??
xChildNamed = (XNamed) UnoRuntime.queryInterface(
XNamed.class,
serviceFactory.createInstance("com.sun.star.text.TextSection", document1));
Also, please elaborate what the following call does?
componentExport(document2, storeProps, tempDoc);
Thanks,
Ali |
|
| Back to top |
|
 |
amohammad Newbie

Joined: 10 Sep 2012 Posts: 3
|
Posted: Mon Sep 10, 2012 9:02 pm Post subject: |
|
|
| Can any one please reply???? its urgent please |
|
| Back to top |
|
 |
amohammad Newbie

Joined: 10 Sep 2012 Posts: 3
|
Posted: Tue Sep 11, 2012 1:58 am Post subject: |
|
|
I have figured out the issue. "serviceFactory" is obtained as follow:
serviceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface( MultiServiceFactory.class, xTextDocument );
and the following code is not needed:
componentExport(document2, storeProps, tempDoc); |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|