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

Inserting images using C#

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
boypula
Newbie
Newbie


Joined: 22 Mar 2006
Posts: 4

PostPosted: Thu Mar 30, 2006 7:50 pm    Post subject: Inserting images using C# Reply with quote

How do you insert an image into a text document using C#? Thanks.
Back to top
View user's profile Send private message
hol.sten
Super User
Super User


Joined: 14 Nov 2004
Posts: 3533
Location: Hamburg, Germany

PostPosted: Sat Apr 01, 2006 6:23 am    Post subject: Re: Inserting images using C# Reply with quote

boypula wrote:
How do you insert an image into a text document using C#?

All I can offer is a java example:
Code:
private void insertImage(String imageName, XComponent document, XTextRange bookmark) {
  try {
    String imageUrl;
    Image image;
    File imageFile = new File(imageName);
    try {
      imageUrl = ("file:///" + imageFile.getCanonicalPath()).replace('\\', '/');
      image = ImageIO.read(imageFile);
    } catch (IOException e) {
      image = null;
      // Handle exception
    }

    short hOrientation = HoriOrientation.LEFT; // Choose among HoriOrientation elements
    short vOrientation = VertOrientation.TOP; // Choose among VertOrientation elements
   
    int imageWidth;
    int imageHeight;
    int enlargement = 10; // Depends on the size of your image and the desired size in the document
    if (image != null) {
      imageWidth = (image.getWidth(null) * enlargement);
      imageHeight = (image.getHeight(null) * enlargement);
      image.flush();
    } else {
      imageWidth = 100;
      imageHeight = 100;
      System.out.println("Something is wrong with the image.");
    }

    TextContentAnchorType oTCAT = null; // Choose among TextContentAnchorType elements
    WrapTextMode oWTM = null; // Choose among WrapTextMode elements

    // Create graphic object
    XMultiServiceFactory xWriterFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, document);
    Object graphicObject = xWriterFactory.createInstance("com.sun.star.text.GraphicObject");
   
    // Set properties
    XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, graphicObject);
    xPropSet.setPropertyValue("GraphicURL", imageUrl);
    xPropSet.setPropertyValue("HoriOrient", new Short(hOrientation));
    xPropSet.setPropertyValue("VertOrient", new Short(vOrientation));
    xPropSet.setPropertyValue("Width", new Integer(imageWidth));
    xPropSet.setPropertyValue("Height", new Integer(imageHeight));
    xPropSet.setPropertyValue("AnchorType", oTCAT);
    xPropSet.setPropertyValue("TextWrap", oWTM);
   
    // Insert graphic object
    XTextContent xGraphicObjectTextContent = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, graphicObject);
    bookmark.getText().insertTextContent(bookmark, xGraphicObjectTextContent, false);
  } catch (com.sun.star.uno.Exception e) {
    // Handle exception
  } catch (com.sun.star.uno.RuntimeException e) {
    // Handle exception
  }
}

Hope it helps anyway.

With kind regards
hol.sten


Last edited by hol.sten on Wed Nov 01, 2006 11:40 am; edited 1 time in total
Back to top
View user's profile Send private message
wangxianlg
Power User
Power User


Joined: 10 Aug 2004
Posts: 67

PostPosted: Tue Jul 11, 2006 11:49 am    Post subject: embedding the images into the file -- v 2.0 Reply with quote

Hi there,

I'm just wondering if you how to embedding the images into the file using java?

Thanks

Alan
Back to top
View user's profile Send private message
hol.sten
Super User
Super User


Joined: 14 Nov 2004
Posts: 3533
Location: Hamburg, Germany

PostPosted: Thu Jul 13, 2006 10:59 am    Post subject: Re: embedding the images into the file -- v 2.0 Reply with quote

wangxianlg wrote:
I'm just wondering if you how to embedding the images into the file using java?

I'm using the above posted code.

With kind regards
hol.sten
Back to top
View user's profile Send private message
aloiziops
Power User
Power User


Joined: 07 Jul 2006
Posts: 52

PostPosted: Wed Nov 01, 2006 5:52 am    Post subject: Reply with quote

I am tryibg to use the code posted above. But I get some error, what the type of graphicObject and xGOProps fiels. They aren't declared into the code.
Back to top
View user's profile Send private message
hol.sten
Super User
Super User


Joined: 14 Nov 2004
Posts: 3533
Location: Hamburg, Germany

PostPosted: Wed Nov 01, 2006 11:39 am    Post subject: Reply with quote

aloiziops wrote:
I am tryibg to use the code posted above. But I get some error

Ups!

aloiziops wrote:
what the type of graphicObject

Declare it with
Code:
Object graphicObject;


aloiziops wrote:
and xGOProps fiels.

Change both occurences of xGOProps to xPropSet.

aloiziops wrote:
They aren't declared into the code.

I fixed my code in my posting above. Thanks for mentioning.

Does it now work for you?

Regards
hol.sten
Back to top
View user's profile Send private message
aloiziops
Power User
Power User


Joined: 07 Jul 2006
Posts: 52

PostPosted: Fri Nov 03, 2006 8:44 am    Post subject: Reply with quote

Hi hol.sten

That's ok. It works.

thanks.
Back to top
View user's profile Send private message
hol.sten
Super User
Super User


Joined: 14 Nov 2004
Posts: 3533
Location: Hamburg, Germany

PostPosted: Fri Nov 03, 2006 10:35 am    Post subject: Reply with quote

aloiziops wrote:
That's ok. It works.

Thanks again for mentioning.

Regards
hol.sten
Back to top
View user's profile Send private message
Juan400
Newbie
Newbie


Joined: 04 Jul 2012
Posts: 2

PostPosted: Fri Jul 20, 2012 11:27 am    Post subject: Re: Inserting images using C# Reply with quote

boypula wrote:
How do you insert an image into a text document using C#? Thanks.


Can you sharee with me the sample in C#?, if you have it
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 Macros and API 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