Search code examples
javajavafxireportcrystal-reports-2010

Maths Equation in Reports


How do I print a math equation written in JavaFX HTML editor? I wrote a math equation in Microsoft Word, then I copied and pasted it to the HTML editor. Now, I would like to print it, is there any other method?


Solution

  • Which JavaFX version are you using ?

    I suppose you pasted this equation as a picture ?

    The next coming versions of JavaFX support MathML :

    • JavaFX 8 Update 192 included in Java 8 Update 192
    • JavaFX 11.

    So if you want to display an equation, I suggest you use MathML. And if you want to save it in a database, you simply have to copy the MathML code.

    Follow this link Java Early Access Download to reach the early access to these versions.

    I don't know Jasper Report but I understand that it uses xml file. Or XML, MathML, HTML, SVG belong to the same family language (SGML) : They are just strings. So you can wrap your HTML + MathML text and formula in an xml expression or may be replace the picture name you used before with these codes. Then you can set WebView or HTMLEditor content using this HTML + MathML code.

    Below, the MathML code to display the following quadratic formula.

    Quadratic formula

    <math display="block"> 
       <mrow> 
          <mi>x</mi> 
          <mo>=</mo> 
          <mfrac> 
             <mrow> 
                <mo>−</mo> 
                <mi>b </mi> 
                <mo>±</mo> 
                <msqrt> 
                   <mrow> 
                      <msup> 
                         <mi>b</mi> 
                         <mn>2</mn> 
                      </msup> 
                      <mo>−</mo> 
                      <mn>4</mn> 
                      <mi>a</mi> 
                      <mi>c</mi> 
                   </mrow> 
                </msqrt> 
             </mrow> 
             <mrow> 
                <mn>2</mn> 
                <mi>a</mi> 
             </mrow> 
          </mfrac> 
       </mrow>
    </math>
    

    Finally, print it :-) How to Print with JavaFX.

    Other documents in that tutorial also show you how to build the browser that implements all what you want.