Export images C#

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
gudaev
Posts: 1
Joined: Wed Mar 30, 2011 11:11 am

Export images C#

Post by gudaev »

Hello,

I have to parse .odt document to html manualy.
I have to save default format of each paragraph and each text portion in it.
In the document I parse, sometimes I meet something like that:

some text IMAGE some text.

So I need to get that image, get its size, and save it.
All images anchor type is char.


Parsing looks like(written in C#):

Code: Select all

OOo.container.XEnumerationAccess xEnumerationAccess =   
                    (OOo.container.XEnumerationAccess )currentDoc.getText();
                OOo.container.XEnumeration xParagraphEnumeration =
                    xEnumerationAccess.createEnumeration();
 while (xParagraphEnumeration.hasMoreElements())
                {
                   
                    uno.Any element = xParagraphEnumeration.nextElement();
             
                    XServiceInfo xinfo = (XServiceInfo)element.Value;
OOo.text.XTextContent xTextElement = (OOo.text.XTextContent)element.Value;
OOo.container.XEnumerationAccess xParaEnumerationAccess =
                                (OOo.container.XEnumerationAccess)xTextElement;

            // create text portion enum
            OOo.container.XEnumeration xTextPortionEnum =
                xParaEnumerationAccess.createEnumeration();

            //for each text portion
            while (xTextPortionEnum.hasMoreElements())
            {
uno.Any content = xTextPortionEnum.nextElement();
                OOo.text.XTextRange xTextPortion =
                    (OOo.text.XTextRange)content.Value;
                OOo.beans.XPropertySet xTextProps = (OOo.beans.XPropertySet)xTextPortion;
                if (xTextProps.getPropertyValue("CharWeight").Value.ToString() == OOo.awt.FontWeight.BOLD.ToString())
                {
                    isBold = true;
                }
                if (xTextProps.getPropertyValue("CharPosture").Value.ToString() == OOo.awt.FontSlant.ITALIC.ToString())
                {
                    isItalic = true;
                }

                portionString = xTextPortion.getString();
                if (portionString == "")
                {
                  // Is an Image there?
                 }
                if (isBold)
                    portionString = "<b>" + portionString + "</b>";
                if (isItalic)
                    portionString = "<i>" + portionString + "</i>";
                HtmlString += portionString;
} 
So I have XTextRange, that contains an image. Am I rigth?
How to get an image from range?

Thanks.
OpenOffice 3.3 on Windows Xp
User avatar
Zizi64
Volunteer
Posts: 11359
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Export images C#

Post by Zizi64 »

Hi,

Here is a OOBasic example from the Hungarian Forum:
http://user.services.openoffice.org/hu/ ... ?f=6&t=645
ExportAllGraphics300dpi.odt
(32.69 KiB) Downloaded 296 times
Maybe it will help you...
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Post Reply