Page 1 of 1

[Solved] Insert image with option "in background" in writer

PostPosted: Mon Aug 11, 2008 8:25 am
by grosenick
I think now I've got it: setting the property "Opaque" to Boolean.FALSE has this effect ...


Hello community,

I've successfully inserted to my writer document using the java uno api.

But the image doesn't have the option "in background" set, so the image is in front of the text.
How can I set this option and put the image behind the text? I don't find any property for that.
(I don't want to set the background image of the page)

Futhermore the write gui allows to place the image "from left" of a page and the user can set the distance from the left side of the page.
I only achieved to set the left margin of the image, but this is not the same.

This is my code:

Code: Select all   Expand viewCollapse view
                // iterate pages
                do {
                    Object graphicObject = xWriterFactory.createInstance("");

                    XTextContent xGOTextContent = (XTextContent)UnoRuntime.queryInterface(XTextContent.class, graphicObject);
                    XPropertySet xGOProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, graphicObject);

                    if (logFinest)
                        helper.dumpPropertySet(xGOProps, "Graphics");

                    xGOProps.setPropertyValue("GraphicURL", imgUrl.toString());
                    xGOProps.setPropertyValue("AnchorType", TextContentAnchorType.AT_PAGE);
                    xGOProps.setPropertyValue("HoriOrient", leftBorder ?
                                                            HoriOrientation.LEFT : HoriOrientation.RIGHT);
                    xGOProps.setPropertyValue("VertOrient", VertOrientation.CENTER);

                    // OO allows to say "hor. position 5mm from left", but I don't find
                    // a way to do that with uno. Using LeftMargin has a similar effect
                    // as long as the image is on the left side of the page ...
                    if (leftBorder)
                        xGOProps.setPropertyValue("LeftMargin", new Integer(500));   // == 5mm
                        xGOProps.setPropertyValue("RightMargin", new Integer(500));  // == 5mm
                    xGOProps.setPropertyValue("TextWrap", WrapTextMode.THROUGHT);
                    xGOProps.setPropertyValue("Width",    new Integer(image.getWidthInMm()));
                    xGOProps.setPropertyValue("Height",   new Integer(image.getHeightInMm()));

                    // insert the image at the cursor's position (by page number)
                    viewCursor.getText().insertTextContent(viewCursor, xGOTextContent, false);

                } while (pageCursor.jumpToNextPage());

Thank you for support!

Re: [Solved] Insert image with option "in background" in writer

PostPosted: Mon Aug 11, 2008 1:56 pm
by Hagar Delest
grosenick wrote:Thank you for support!

You're welcome! :D
Anyway, thanks for the follow up. This post is mainly to remove it from the unanswered posts list!