OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

hyperlinking a image in writer

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
creativemadhan
Power User
Power User


Joined: 28 Jul 2006
Posts: 54
Location: Bangalore

PostPosted: Mon Sep 04, 2006 10:53 pm    Post subject: hyperlinking a image in writer Reply with quote

The follwing code adds a text and image in the writer and te image will have a hyper link
Code:

import com.sun.star.beans.*;
import com.sun.star.lang.*;
import com.sun.star.text.*;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.frame.XComponentLoader;

public class link extends java.lang.Object {
       public static void main(String[] args) throws java.lang.Exception {

    // get the Textdocument
    // get the Text document component
    com.sun.star.uno.XComponentContext xRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
            System.out.println("Connected to a running office ...");
            com.sun.star.lang.XMultiComponentFactory xRemoteServiceManager = xRemoteContext.getServiceManager();
         
        // get the Desktop, we need its XComponentLoader interface to load a new document
        Object desktop = xRemoteServiceManager.createInstanceWithContext(
            "com.sun.star.frame.Desktop", xRemoteContext);

       // query the XComponentLoader interface from the desktop
        XComponentLoader xComponentLoader = (XComponentLoader)UnoRuntime.queryInterface(
            XComponentLoader.class, desktop);

        // create empty array of PropertyValue structs, needed for loadComponentFromURL
        PropertyValue[] loadProps = new PropertyValue[0];
   
        // load new writer file
        XComponent xComponent = xComponentLoader.loadComponentFromURL(
            "private:factory/swriter", "_blank", 0, loadProps);

    XTextDocument xTextDocument = (XTextDocument)
        UnoRuntime.queryInterface(XTextDocument.class, xComponent);

    // get the document container
    XText xText = xTextDocument.getText();

    // Create a document cursor and remember it.
    XTextCursor curText = xText.createTextCursor();           

    // Access the text document's multi service factory.
    XMultiServiceFactory mxDocFactory = (XMultiServiceFactory)
        UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);

    xText.insertString(curText, "Graphic Object", false);
        xText.insertControlCharacter(
            curText, ControlCharacter.PARAGRAPH_BREAK, false);

        // ------------------------------
    // create the GraphicObject and get the XTextContent interface

    Object oGraphicObject =
        mxDocFactory.createInstance ("com.sun.star.text.GraphicObject");

    XTextContent xGraphicContent = (XTextContent)
        UnoRuntime.queryInterface(XTextContent.class, oGraphicObject);

        // ------------------------------
    // set the graphic object property

    XPropertySet xGraphicProps = (XPropertySet)
        UnoRuntime.queryInterface(XPropertySet.class, xGraphicContent);

    // TextContent properties

    xGraphicProps.setPropertyValue(
        "AnchorType", TextContentAnchorType. AT_PARAGRAPH);

    // BaseFrame properties

    xGraphicProps.setPropertyValue("BackColor", new Integer(0x0000ff));
    xGraphicProps.setPropertyValue("BackTransparent", new Boolean(false));

        com.sun.star.awt.Size aSize = new com.sun.star.awt.Size();
        aSize.Height = 1800;
        aSize.Width = 1800;
    xGraphicProps.setPropertyValue("Size", aSize);

    xGraphicProps.setPropertyValue(
        "GraphicURL", "file:///opt/star.gif");
    xGraphicProps.setPropertyValue("AdjustLuminance", new Short((short)-5));
    xGraphicProps.setPropertyValue("Transparency", new Short((short) 20));
        xGraphicProps.setPropertyValue("HyperLinkURL", "http://www.edurite.com");
     xText.insertTextContent(curText, xGraphicContent, false);

    System.exit(0);
    }
}



I want to make the same thing in impress.... can any one give me an idea
_________________
Madhan Ponnusamy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group