Hi basically I am using the OpenOffice SDK (3.1.1) to create a new Writer
document. I add images with the following code, passing in the XText (which
in this case is an XText from a XTextFrame).
I pass in a width, and height... and if I pass in an X/Y coordinate i change
the anchor to "FRAME":
Object newImage =
xWriterFactory_dest.createInstance("com.sun.star.text.TextGraphicObject");
XTextContent xNewTextContent = (XTextContent)
UnoRuntime.queryInterface(XTextContent.class, newImage);
XTextCursor xTextCursor = xFrameText.createTextCursor();
xTextCursor.gotoEnd(false);
XPropertySet xProps =
(XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, newImage);
System.out.println("GraphicURL: " + strImgFileName);
// helper-stuff to let OOo create an internal name of the graphic
// that can be used later (internal name consists of various
checksums)
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(strImgFileName.getBytes(), 0, strImgFileName.length());
String internalName = new BigInteger(1, md.digest()).toString(16);
XNameContainer xBitmapContainer = (XNameContainer)
UnoRuntime.queryInterface(
XNameContainer.class, xWriterFactory_dest.createInstance(
"com.sun.star.drawing.BitmapTable"));
xBitmapContainer.insertByName(internalName, strImgFileName);
String internalURL =
(String)(xBitmapContainer.getByName(internalName));
xProps.setPropertyValue("GraphicURL", internalURL);
if (xTextFrame == null) {
xProps.setPropertyValue("AnchorType",
TextContentAnchorType.AT_PARAGRAPH);
} else {
xProps.setPropertyValue("AnchorType",
TextContentAnchorType.AT_FRAME);
}
xProps.setPropertyValue("Width", width);
xProps.setPropertyValue("Height", height);
if (centreImage == true) {
int pos_x = (frame_size.Width / 2) - (width / 2) - 300;
// update frame width with the new dimensions.
xProps.setPropertyValue("HoriOrient", new
Short(HoriOrientation.NONE));
xProps.setPropertyValue("HoriOrientPosition", new
Integer(pos_x));
} else {
int pos_x = 1000;
if (x == (-1)) {
xProps.setPropertyValue("HoriOrient", new
Short(HoriOrientation.NONE));
xProps.setPropertyValue("HoriOrientPosition", new
Integer(pos_x));
} else {
xProps.setPropertyValue("HoriOrient", new
Short(HoriOrientation.NONE));
xProps.setPropertyValue("HoriOrientPosition", new
Integer(x));
}
if (y == (-1)) {
xProps.setPropertyValue("VertOrient", new
Short(VertOrientation.TOP));
// xProps.setPropertyValue("VertOrientPosition", new
Integer(pos_y));
} else {
xProps.setPropertyValue("VertOrient", new
Short(HoriOrientation.NONE));
xProps.setPropertyValue("VertOrientPosition", new
Integer(y));
}
}
xFrameText.insertTextContent(xTextCursor, xNewTextContent, false);
// remove unnecessary object reference
xBitmapContainer.removeByName(internalName);
}
I save the OpenOffice document (which does display properly) like so:
and then save the same document to MS Word before closing.
XStorable xStorable =
(XStorable)UnoRuntime.queryInterface(XStorable.class,
xTextDocument_dest);
PropertyValue[] storeProps = new PropertyValue[1];
storeProps[0] = new PropertyValue();
storeProps[0].Name = "FilterName";
storeProps[0].Value = "MS Word 97";
String filename = "file:///tmp/test.doc";
System.out.println("MS Word filename: " + filename);
xStorable.storeAsURL(filename, storeProps);
tora - Takamichi Akiyama wrote:
>
> Are you using vertical writing? If so, there is a bug which
> misinterprets the position of graphic object during importing
> from and exporting into Microsoft Word 97-2003.
>
> http://qa.openoffice.org/issues/show_bug.cgi?id=86769
>
> http://www.openoffice.org/nonav/issues/showattachment.cgi/61766/i86769_wordarts_01_doc_snapshots.png
>
> How are you trying to achieve your needs? Like this?
> 1. Prepare OpenOffice.org 3.1.1 on MacOS X 10.6.2.
> 2. Start your Java program to create an empty Writer document or
> to open an existing Writer document and then
> to import a graphic image file.
> 3. How do you save the Writer document as a Word file?
> by hand or by the Java program?
> 4. What file type or FilterName do you use for saving the document?
> Microsoft Word 97/2000/XP writer_MS_Word_97
> Microsoft Word 2003 XML writer_MS_Word_2003_XML
> Microsoft Word 2007 XML writer_MS_Word_2007
> 5. Anything else that you have noticed...
>
> There might be several possibilities, I guess:
> (a) Something in your Java program.
> (b) Bugs in OpenOffice.org 3.1.1.
> (c) Bugs in Microsoft Office running on Macintosh.
>
> What will happen with your environment?
> 1. Manually create an empty Writer document.
> 2. Manually import a graphic image.
> 3. Move it and alter its attributes.
> 4. Save it as Word 97/2000/XP and/or Word 2003 XML.
> 5. Open it with your Word 2007/2008.
>
> Tora
>
> Chris Fleischmann wrote:
>> Thanks for responding, I have since tried playing around with the
>> orientation
>> settings, but alas, its still not keeping the x/y position from the
>> paragraph anchor when I open it up in Word ... See the picture properties
>> here for one of my images in openoffice 3.1.1:
>>
>> http://old.nabble.com/file/p26992864/Screen%2Bshot%2B2010-01-02%2Bat%2B11.46.15%2BPM.png
>>
>>
>> Unfortunately, it still moves to the TOP of the paragraph anchor, and
>> also
>> moves to the leftmost position possible.
>>
>> So given the paragraph anchor, the image moves to the top left position
>> of
>> the anchor.
>>
>> Thanks in advance for any other tips.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
>
--
View this message in context:
http://old.nabble.com/Please-help%3A-saving-document-as-DOC-format%2C-then-opening%2C-losing-position-properties-for-TextGraphicObject-tp26989671p26997843.html
Sent from the openoffice - dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]