Hello... I have since tried the following code, which aims to do just that... It add the picture to a frame, The frame is either anchored to a paragraph or frame...Thats is, I have a parent frame which is anchored to a particular page, with PAGE anchoring... Inside that frame is the "NEW" frame that now "holds" the image.
This all works in OpenOffice... The document works perfectly. In MS Word... I don't see the images or new frames at all. See code here: protected XTextFrame getTextFrame(XText xText, int width, int height, int x, int y, TextContentAnchorType anchorType, short horiOrient, short vertOrient) throws Exception { Object textFrame = xWriterFactory_dest.createInstance("com.sun.star.text.TextFrame"); XTextFrame xTextFrame = (XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, textFrame); XPropertySet xShapeProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextFrame); BorderLine aBorderLine = new BorderLine(); aBorderLine.OuterLineWidth = 1; aBorderLine.Color = new Integer(0x000000); xShapeProps.setPropertyValue("TopBorder", aBorderLine); xShapeProps.setPropertyValue("BottomBorder", aBorderLine); xShapeProps.setPropertyValue("LeftBorder", aBorderLine); xShapeProps.setPropertyValue("RightBorder", aBorderLine); xShapeProps.setPropertyValue("AnchorType", anchorType); // Setting the vertical and horizontal position xShapeProps.setPropertyValue("FrameIsAutomaticHeight", new Boolean(false)); xShapeProps.setPropertyValue("SizeType", new Short((short)1)); xShapeProps.setPropertyValue("HoriOrient", new Short(horiOrient)); xShapeProps.setPropertyValue("VertOrient", new Short(vertOrient)); xShapeProps.setPropertyValue("FrameWidthAbsolute", new Integer(width)); xShapeProps.setPropertyValue("FrameHeightAbsolute", new Integer(height)); xShapeProps.setPropertyValue("LeftBorderDistance", new Integer(0)); xShapeProps.setPropertyValue("RightBorderDistance", new Integer(0)); xShapeProps.setPropertyValue("TopBorderDistance", new Integer(0)); xShapeProps.setPropertyValue("BottomBorderDistance", new Integer(0)); // Setting the vertical and horizontal position if (horiOrient == HoriOrientation.NONE) { xShapeProps.setPropertyValue("HoriOrientPosition", new Integer(x)); } if (vertOrient == VertOrientation.NONE) { xShapeProps.setPropertyValue("VertOrientPosition", new Integer(y)); } xShapeProps.setPropertyValue("TextWrap", WrapTextMode.NONE); xText.insertTextContent(xText.getEnd(), xTextFrame, false); return xTextFrame; } And the addImage method has since been changed too: /** * Use this method to add a JPG to the textframe. * * @param strImgFileName The image to add. * @param width The width of the image. * @param height The height of the image. * @param centreImage Centre the image. * @param x The position on the frame from the left margin (of the frame). * @param y The position on the frame from the top margin (of the frame). * * @throws Exception */ private void addJPGImage(XTextFrame xTextFrame, String strImgFileName, int width, int height, boolean centreImage, int x, int y) throws Exception { // allocate an xText object in case it's required. XText xText = xTextDocument_dest.getText(); // Test whether we need to assign a different text frame. if (xTextFrame != null) { xFrameText = (XText) UnoRuntime.queryInterface(XText.class, xTextFrame); } XTextFrame tmp_xTextFrame = null; if (centreImage == true) { int anchor = -1; if (xTextFrame != null) { anchor = TextContentAnchorType.AT_FRAME_value; } else { anchor = TextContentAnchorType.AT_PARAGRAPH_value; } tmp_xTextFrame = getTextFrame(xFrameText.getText(), width, height, x, y, TextContentAnchorType.fromInt(anchor), HoriOrientation.CENTER, VertOrientation.TOP); } else { int pos_x = -1; int pos_y = -1; short horiOrient = HoriOrientation.NONE; short vertOrient = VertOrientation.NONE; int anchor = -1; if (xTextFrame != null) { anchor = TextContentAnchorType.AT_FRAME_value; } else { anchor = TextContentAnchorType.AT_PARAGRAPH_value; } // The X orientation, is moved 10mm to the right... move it back. if (x == (-1)) { horiOrient = HoriOrientation.NONE; pos_x = 0; } else { horiOrient = HoriOrientation.NONE; pos_x = x - 1000; } if (y == (-1)) { vertOrient = VertOrientation.TOP; } else { vertOrient = VertOrientation.NONE; pos_y = y; } tmp_xTextFrame = getTextFrame(xFrameText.getText(), width, height, pos_x, pos_y, TextContentAnchorType.fromInt(anchor), horiOrient, vertOrient); } XText xFrameText2 = (XText) UnoRuntime.queryInterface(XText.class, tmp_xTextFrame); // add the height of the image to the current height. current_height += height; Object newImage = xWriterFactory_dest.createInstance("com.sun.star.text.TextGraphicObject"); XTextContent xNewTextContent = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, newImage); XTextCursor xTextCursor = xFrameText2.createTextCursor(); xTextCursor.gotoEnd(false); XPropertySet xProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, newImage); System.out.println("GraphicURL: " + strImgFileName); // xProps.setPropertyValue("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); xProps.setPropertyValue("AnchorType", TextContentAnchorType.AT_FRAME); xProps.setPropertyValue("Width", width - 5); xProps.setPropertyValue("Height", height - 5); xProps.setPropertyValue("HoriOrient", new Short(HoriOrientation.CENTER)); xProps.setPropertyValue("VertOrient", new Short(VertOrientation.CENTER)); xFrameText2.insertTextContent(xTextCursor, xNewTextContent, false); // remove unnecessary object reference xBitmapContainer.removeByName(internalName); } Image 1: Is the outerframe properties.: http://old.nabble.com/file/p26997929/Screen%2Bshot%2B2010-01-03%2Bat%2B11.19.41%2BAM.png Image 2: Is the innerframe (containing the images) properties.: http://old.nabble.com/file/p26997929/Screen%2Bshot%2B2010-01-03%2Bat%2B11.20.46%2BAM.png Image 3: The picture properties.: http://old.nabble.com/file/p26997929/Screen%2Bshot%2B2010-01-03%2Bat%2B11.21.12%2BAM.png vito smolej wrote: > > What about putting the graphics into a container - a text box for > instance -, which is able to listen to your prayers (g)? > > Regards > > Vito > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@openoffice.org > For additional commands, e-mail: dev-h...@openoffice.org > > > -- 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-tp26989671p26997929.html Sent from the openoffice - dev mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@openoffice.org For additional commands, e-mail: dev-h...@openoffice.org