Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Apr 20, 2023 7:53 am

I'm using spire office v8.2.0 for .net (c#) win10 64bit
I want to export MathType out of a word document and/or powerpoint documents.
So far my best attempts find that MathType equations appear as text="" textranges in powerpoint and (vector) images in word.
Within word and powerpoint I can copy-paste it like text. From within spire I can't access any indication of the equation's content.

I can't do any of the following and any of these would help:
-export equations (as text) from either powerpoint or word using spire
-distinguish textranges that are actually MathType in powerpoint from empty text ranges
-save MathType textranges as images in powerpoint
If you know how please post some code demonstrating it, I can't figure it out.
Thanks.

joekatana
 
Posts: 6
Joined: Thu Apr 20, 2023 7:41 am

Thu Apr 20, 2023 12:09 pm

Hi,


Thanks for your inquiry.
Our Spire.DOC will parse the mathtype equations into DocOleObject, it is unable to obtain the text. If you need to convert the equation into an image format, you can use the following code as a reference:
Code: Select all
            Document doc = new Document();
            doc.LoadFromFile("test.docx");

            int i = 0;
            foreach (Spire.Doc.Section section in doc.Sections)
            {
                foreach (DocumentObject obj in section.Body.ChildObjects)
                {
                    if (obj is Paragraph)
                    {
                        Paragraph para = obj as Paragraph;
                        foreach (DocumentObject cobj in para.ChildObjects)
                        {
                            if (cobj is DocOleObject)
                            {
                                //Find DocOleObject object and save it
                                DocOleObject ole = cobj as DocOleObject;
                                ole.OlePicture.Image.Save(string.Format("image-{0}.png",i++));
                            }
                        }
                    }
                }
            }


If the code does not meet your requirement or you have any other questions, just feel free to contact us.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Thu Apr 20, 2023 6:20 pm

Thanks. What about in powerpoint? Is there any way to tell the difference between MathType and regular text?

joekatana
 
Posts: 6
Joined: Thu Apr 20, 2023 7:41 am

Fri Apr 21, 2023 3:14 am

Hi,

Thanks for your inquiry.
Please see the following code for reference.
Code: Select all
            Presentation ppt = new Presentation();
            ppt.LoadFromFile(@"test.pptx");
            int i = 0;
            foreach (ISlide slide in ppt.Slides)
            {
                foreach (IShape shape in slide.Shapes)
                {
                    if (shape is IOleObject)
                    {
                        shape.SaveAsImage().Save(string.Format("test-{0}.png",i), ImageFormat.Png);
                    }
                }
            }
            ppt.Dispose();

For your second question, the math type equations will be parsed into ole Object, the regular text will be parsed into TextRange object. Please refer to the following code.
Code: Select all
            Document doc = new Document();
            doc.LoadFromFile(@"test.docx");

            int i = 0;
            foreach (Spire.Doc.Section section in doc.Sections)
            {
                foreach (DocumentObject obj in section.Body.ChildObjects)
                {
                    if (obj is Paragraph)
                    {
                        Paragraph para = obj as Paragraph;
                        foreach (DocumentObject cobj in para.ChildObjects)
                        {
                            if (cobj is DocOleObject)
                            {
                                //Find DocOleObject object and save it
                                DocOleObject ole = cobj as DocOleObject;
                                ole.OlePicture.Image.Save(string.Format("image-{0}.png", i++));
                            }
                            if (cobj is Spire.Doc.Fields.TextRange)
                            {
                                Spire.Doc.Fields.TextRange range = cobj as Spire.Doc.Fields.TextRange;
                                string text =range.Text;
                                // do something
                            }
                        }
                    }
                }
            }

If you have any further questions, just feel free to contact us.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.Doc