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.

Mon Apr 06, 2020 9:46 pm

Hello Support

First Time We are using the Spire.Doc for our customer . They have one docx file where there is mathematics questions and Mathematics Images for the students .
So these question are in very plain docx file and Our job is read the all text and images including equation from the docs and then insert in data base as well as show in Html Webpage.

So we designed the docx template to identify questions , answers, correct answers and description using styling for e.g. questions are ABC Title format, answer groups are Heading3 format, correct answer is Subtitle format and description is in Heading 2 format .

In code while reading the text from doc we shall use the logic like if style === ABC title then it is Questions,
if style === Heading 3 then these are answer group like this .

Now the problem is 6√5 cm2 not able to extract in code using spire doc , only cm2 is coming . Please help (Doc is attached)

We are using .Net Framework 4.7.2 and Install-Package Spire.Doc -Version 8.3.15

deonticsoft
 
Posts: 5
Joined: Mon Apr 06, 2020 9:17 pm

Tue Apr 07, 2020 3:18 am

Hello,

Thanks for your inquiry.
Please refer to the following code to read the math equations. If this is not what you want, please provide more detailed information about your needs.
Code: Select all
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile(@"questionEnglish.docx");
            string questions = "";
            string answerGroups = "";
            string correctAnswer = "";
            string description = "";
            foreach (Section section in doc.Sections)
            {
                foreach (Paragraph paragraph in section.Paragraphs)
                {
                    switch (paragraph.StyleName)
                    {
                        case "Title":
                            questions += GetText(paragraph);
                            break;
                        case "Heading3":
                            answerGroups += GetText(paragraph);
                            break;
                        case "Subtitle":
                            correctAnswer += GetText(paragraph);
                            break;
                        case "Heading2":
                            description += GetText(paragraph);
                            break;
                        default: break;
                    }
                }
            }
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.AppendLine("Questions:");
            stringBuilder.AppendLine(questions);
            stringBuilder.AppendLine("Answer Groups:");
            stringBuilder.AppendLine(answerGroups);
            stringBuilder.AppendLine("Correct Answer:");
            stringBuilder.AppendLine(correctAnswer);
            stringBuilder.AppendLine("Description:");
            stringBuilder.AppendLine(description);
            File.WriteAllText("text.txt", stringBuilder.ToString());
        }

        public static string GetText(Paragraph para)
        {
            StringBuilder stringBuilder = new StringBuilder();
            foreach (DocumentObject obj in para.ChildObjects)
            {
                if (obj is OfficeMath)
                {
                    stringBuilder.Append((obj as OfficeMath).ToMathMLCode());
                }
                else if (obj is TextRange)
                {
                    stringBuilder.Append((obj as TextRange).Text);
                }
            }
            stringBuilder.AppendLine();
            return stringBuilder.ToString();
        }


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Tue Apr 07, 2020 2:27 pm

Hello Support
Thanks a lot for your reply . This code is working perfectly . But while working in this it is limited in two case .
Our docx file is consists of multiple choice questions and its answers list . But this code only read one question and its answer list or this it read all the question text at a time and answer list one time .

We want to display in html like questions and its answer list , corrected answer . And again another question and its answer list like repeatedly .

For e.g like below
Q1 :
What is correct answer of the below Question ---> Title Style is Question
5 squre root 2 cm2
5 squre root 2 cm2 ----> The Style is Heading 3 for answer list
5 squre root 2 cm2
5 squre root 2 cm2
Ans: A -----> The Style is Subtitle for correct answer
Video: Youtube Urls ---> The style is normal for description
Q2:
What is the result of below Question ---> Title Style is Question
\mathrm{6\sqrt5\ } cm2 ----> The Style is Heading 3 for answer list
\mathrm{4}\sqrt\mathrm{5} cm2
\mathrm{10\sqrt5}cm2
Ans: B -----> The Style is Subtitle for correct answer
Video: Youtube Urls ---> The style is normal for description

Now what is going on

foreach (Section section in doc.Sections) // here whole document contents are looping at one section

foreach (Paragraph paragraph in section.Paragraphs) //each and every line is taking as a paragraph .

So it's become very difficult to me to take question and its answer list in one loop and in a list in C#

---------------------------------------------------------------------------------------------------------Second Help ---------------------------------------------------------------------------------
This is for english version of docx , another same style and category for Hindi Version whih fonts are Kruti Dev 010

We have attached both file , it's is very urgent for our customer , please help .
Then we are ready to use the spire doc permanently .
Please reply along with code sample ,please

deonticsoft
 
Posts: 5
Joined: Mon Apr 06, 2020 9:17 pm

Wed Apr 08, 2020 5:52 am

Hello,

Thanks for your feedback.
Attached are the code samples for your two files, please check. If you have further questions, please provide your input file along with your desired output, so that we could provide you with the corresponding solution.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Wed Apr 08, 2020 11:56 pm

Hello Support

We are very very happy the instance support and reply with code sample you are providing us and helping us implementing the spire doc in our client application.

Please help us in the two scenario :

1) Our main aim is to show mathematics equation in html page and then this will be insert in database .

2) Second is the hindi font Kruti Dev 010 . Which is not displaying properly in web page , please have a look the attached images .

How to extract the mathematics equations correctly and How to load the Hindi fonts properly from DOC to browser .

Please have a look at the attached images the square root or root of the element symbols are not loading .

Anything need to do for the equation , please help

deonticsoft
 
Posts: 5
Joined: Mon Apr 06, 2020 9:17 pm

Thu Apr 09, 2020 7:02 am

Hello,

Thanks for your feedback.
How did you render the extracted MathML code into math equations in web page? To help us better look into your issue, could you please share your full code or a runnable project with us? You could send it to us(support@e-iceblue.com) via email.
As for displaying Hidi font in web pages, sorry this doesn't belong to the features of our product. But I searched some technical forums and finally found a solution that can display special fonts. Below is the sample html code for reference.
Code: Select all
<!DOCTYPE html>
<html>
   <head>
      <meta charset="utf-8">
      <title></title>
      <style>
         @font-face {
          font-family: 'KrutiDev010';
          /* The url of you font file */
          src: url('K010.ttf');
         }
      </style>
   </head>
   <body>
      <p style="font-family: KrutiDev010;">,d lef}ckgq f=Hkqt dk ifjeki 18 lseh gSA mldh ik”oZ Hkqtk rFkk vk/kkj dk vuqikr 7 : 4 gSA rn~uqlkj] ml f=Hkqt dk {ks=Qy fdruk gS\</p>
   </body>
</html>


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Thu Apr 09, 2020 9:17 pm

Dear Support

A lots of thanks , my hindi fonts are loading fine on the browser but this is my bad luck. I am not able to achieve the mathematics equation to display over Html .

I have send one email with code text files and also the word document files , please help , please

our email address : solutions at deonticsoft dot com

Please reply there

deonticsoft
 
Posts: 5
Joined: Mon Apr 06, 2020 9:17 pm

Fri Apr 10, 2020 9:00 am

Hello,

Thanks for your information via email.
Actually, our Spire.Doc is based on the Microsoft Word. And the MathML code of the math equation extracted by our product contains a namespace, such as "mml:". After further investigation, I found the MathML code with namespace cannot be displayed normally on the web page. Thus, we recommend you remove the namespace contained in the extracted MathML code, like the following code. Here I also uploaded my testing project for your reference.
Code: Select all
//......
if (obj is OfficeMath)
{
    string temp = (obj as OfficeMath).ToMathMLCode();
    string mathMLCode = temp.Replace("mml:", "");
    stringBuilder.Append(mathMLCode);
}
//......


Meanwhile, I noticed that some math equations in your files are Ole objects, as shown in the attached screenshot. In document structure, the math is rendered as an image in Ole Object. Our Spire.Doc doesn’t support extracting the MathML code from image. You could get the math image by the following code. Hope you can understand.
Code: Select all
//......
if (obj.DocumentObjectType == DocumentObjectType.OleObject)
{
    (obj as DocOleObject).OlePicture.Image.Save("img.png");
}
//......


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Fri Apr 10, 2020 12:36 pm

Hello Support

A lots of thanks to you, we are so happy and glad and now it is working fine . We are working using spire doc . Thanks again for the support .

deonticsoft
 
Posts: 5
Joined: Mon Apr 06, 2020 9:17 pm

Mon Apr 13, 2020 1:11 am

Hello,

Thanks for your feedback.
If you need further assistance, just feel free to contact us.
Wish you all the best!

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.Doc