Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4033284
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:49:45+00:00 2026-05-20T11:49:45+00:00

I am using openoffice sdk to get all info from doc file, what I

  • 0

I am using openoffice sdk to get all info from doc file, what I need now is to be able to extract all images in a doc file and save them as images png or gif.

I am using Java, Is there any working example?

thanks;

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:49:46+00:00Added an answer on May 20, 2026 at 11:49 am

    Here it is example how to extract images from MS Word/OpenOffice documents. It is written in C# but it trivial to convert it to Java.

    link: http://blog-of-darius.blogspot.com/2011/03/extract-images-from-word-openoffice.html

    Updated:
    I converted code to Java

    import com.sun.star.beans.PropertyValue;
    import com.sun.star.beans.XPropertySet;
    import com.sun.star.comp.helper.Bootstrap;
    import com.sun.star.comp.helper.BootstrapException;
    import com.sun.star.container.XNameAccess;
    import com.sun.star.frame.XComponentLoader;
    import com.sun.star.graphic.XGraphic;
    import com.sun.star.graphic.XGraphicProvider;
    import com.sun.star.io.IOException;
    import com.sun.star.lang.IllegalArgumentException;
    import com.sun.star.lang.XComponent;
    import com.sun.star.lang.XMultiComponentFactory;
    import com.sun.star.lang.XServiceInfo;
    import com.sun.star.text.XTextDocument;
    import com.sun.star.text.XTextGraphicObjectsSupplier;
    import com.sun.star.uno.Exception;
    import com.sun.star.uno.UnoRuntime;
    import com.sun.star.uno.XComponentContext;
    import com.sun.star.util.XCloseable;
    
    public class Program {
    
        public static void exportGraphicObject(XGraphicProvider xGraphicProvider, XGraphic xGraphic, String fileName) throws Exception {
            if (xGraphicProvider == null){
                throw new Exception("XGraphicProvider is null.");
            }
    
            if (xGraphic == null){
                throw new Exception("XGraphic is null.");
            }
    
            PropertyValue[] properties = new PropertyValue[2];
            properties[0] = new PropertyValue();
            properties[0].Name = "URL";
            properties[0].Value = fileName;
            properties[1] = new PropertyValue();
            properties[1].Name = "MimeType";
            properties[1].Value = "image/" + fileName.trim().substring(fileName.length() - 3);
    
            xGraphicProvider.storeGraphic(xGraphic, properties);
        }
    
        public static void exportAllEmbeddedGraphics(XGraphicProvider xGraphicProvider, XTextDocument xTextDocument, String outDir) throws Exception {
            if (xGraphicProvider == null){
                throw new Exception("XGraphicProvider is null.");
            }
    
            if (xTextDocument == null){
                throw new Exception("XTextDocument is null.");
            }
    
            XTextGraphicObjectsSupplier xTextGraphicObjectsSupplier = (XTextGraphicObjectsSupplier) UnoRuntime.queryInterface(
                    XTextGraphicObjectsSupplier.class, xTextDocument);
    
            XNameAccess xNameAccess = xTextGraphicObjectsSupplier.getGraphicObjects();
            if (xNameAccess != null && xNameAccess.hasElements()) {
                String[] names = xNameAccess.getElementNames();
    
                for (int i = 0; i < names.length; i++) {
                    Object oGraphics = xNameAccess.getByName(names[i]);
    
                    XServiceInfo xServiceInfo = (XServiceInfo)UnoRuntime.queryInterface(
                            XServiceInfo.class, oGraphics);
                    if (xServiceInfo != null
                            && xServiceInfo.supportsService("com.sun.star.text.TextContent")
                            && xServiceInfo.supportsService("com.sun.star.text.TextGraphicObject")) {
    
                        XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(
                                XPropertySet.class, oGraphics);
                        String url = (String) xPropertySet.getPropertyValue("GraphicURL");
    
                        PropertyValue[] properties = new PropertyValue[1];
                        properties[0] = new PropertyValue();
                        properties[0].Name = "URL";
                        properties[0].Value = url;
    
                        XGraphic xGraphic = xGraphicProvider.queryGraphic(properties);
                        if (xGraphic != null){
                            //String fileName = UUID.randomUUID() + ".png";
                            String fileName = names[i] + ".png";
                            System.out.println("Export: " + names[i]);
                            System.out.println("Filename: " + outDir + fileName);
    
                            exportGraphicObject(xGraphicProvider, xGraphic, outDir + fileName);
    
                            xGraphic = null;
                        }
    
                        xServiceInfo = null;
                    }
    
                    oGraphics = null;
                }
    
                names = null;
                xNameAccess = null;
            }
    
            if (xTextGraphicObjectsSupplier != null)
                xTextGraphicObjectsSupplier = null;
        }
    
        public static void main(String[] args) throws Exception {
            String fileName = "file:///C:/code/_other/java-OOo/test.odt";
            String outDir = "file:///C:/code/_other/java-OOo/out/";
    
            XComponentContext xContext = null;
            XMultiComponentFactory xMultiComponentFactory = null;
            Object oDesktop = null;
            XComponentLoader xComponentLoader = null;
            XGraphicProvider xGraphicProvider = null;
    
            System.out.println("Starting OOo.");
            try {
                xContext = Bootstrap.bootstrap();
            } catch (BootstrapException e) {
                System.out.println("Boostrap failed! Failed to start OpenOffice.");
                return;
            }
    
            xMultiComponentFactory  = (XMultiComponentFactory) xContext.getServiceManager();
            oDesktop = xMultiComponentFactory.createInstanceWithContext(
                    "com.sun.star.frame.Desktop", xContext);
            xComponentLoader = (XComponentLoader)UnoRuntime.queryInterface(
                    com.sun.star.frame.XComponentLoader.class, oDesktop);
            if (xComponentLoader == null) {
                System.out.println("Failed to create XComponentLoader");
                return;
            }
    
            try {
                Object oGraphicProvider = xMultiComponentFactory.createInstanceWithContext(
                        "com.sun.star.graphic.GraphicProvider", xContext);
                xGraphicProvider = (XGraphicProvider) UnoRuntime.queryInterface(
                        XGraphicProvider.class, oGraphicProvider); 
            } catch (Exception e) {
                System.out.println("Failed to create XGraphicProvider!");
                return;
            }
    
            PropertyValue[] properties = new PropertyValue[2];
            properties[0] = new PropertyValue();
            properties[0].Name = "Hidden";
            properties[0].Value = false; // put true to hide OpenOffice window
            properties[1] = new PropertyValue();
            properties[1].Name = "CharacterSet";
            properties[1].Value = "Unicode (UTF-8)";
    
            XComponent document = null;
            try {
                document = xComponentLoader.loadComponentFromURL(fileName, "_blank", 0, properties);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
    
            XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(
                    XTextDocument.class, document);
            exportAllEmbeddedGraphics(xGraphicProvider, xTextDocument, outDir);
    
            XCloseable xCloseable = (XCloseable)UnoRuntime.queryInterface(
                    XCloseable.class, xContext);
            if(xCloseable != null)
            {
                xCloseable.close(true);
                xCloseable = null;
            } 
    
            xGraphicProvider = null;
            xComponentLoader = null;
            oDesktop = null;
            xMultiComponentFactory = null;
            xContext = null;
    
            try {
                Runtime.getRuntime().exec("tskill soffice");
            } catch (java.io.IOException e) {
                e.printStackTrace();
            } 
    
            System.out.println("Done.");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Creating, opening and printing a word file from C++ Hi, I need
I am using OpenOffice uno api to iterate through all text in writer document.
I have downloaded and installed the OpenOffice SDK 3.3.x and I cannot find the
I need to convert an excel spreadsheet to PDF file. I looked for in
My point is that using either pod (from appy framework, which is a pain
I have an old website developed in classic ASP, I need to add openoffice
I'm working on a c# project where I get input from Office documents, and
I'm using Delphi 7 and I'd like to export the contents of a list
Does anyone know of a good Java Microsoft Office API capable or running on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.