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

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
grosenick
Posts: 3
Joined: Sat Jul 12, 2008 3:48 pm

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

Post 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 com.sun.star.text.GraphicObect 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

                // iterate pages
                do {
                    Object graphicObject = xWriterFactory.createInstance("com.sun.star.text.GraphicObject"); 

                    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
                    else
                        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!
OOo 2.4.X on openSuse 11 + Windows XP
User avatar
Hagar Delest
Moderator
Posts: 32658
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

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

Post 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!
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
Post Reply