简体   繁体   中英

Math equations support in xhtml to pdf conversion in Java

I´m trying to convert my xhtml code to pdf using ItextRenderer, but the problem is that the math equations are not well converted.I´m using mathjax to see the equations in all browsers:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><script type="text/javascript"src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=MML_HTMLorMML"/>

This is my html code:

<math xmlns:xlink="http://www.w3.org/1999/xlink" overflow="scroll">
 <msup xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">
   <mrow>
     <mfenced separators="|">
       <mrow>
         <mi>x</mi>
         <mo>+</mo>
         <mi>a</mi>
      </mrow>
    </mfenced>
  </mrow>
  <mrow>
    <mi>n</mi>
  </mrow>

An the html pdf converter code is this:

OutputStream os = new FileOutputStream("outputPDF.pdf");
 ITextRenderer renderer = new ITextRenderer();
 String url = new File("inputHtml.html").toURI().toURL().toString();
 renderer.setDocument(url);
 renderer.layout();
 renderer.createPDF(os);
 os.close();

The problem is that in the pdf all works except the equation.This is the equation in pdf Equation in pdf

Is there any way to apply functions in pdf?or another way in Java?Thank you!!

You might be able to change the MathJax output formats . Rather than generate xhtml you could make it generate SVG output. It might also be worth trying the HTML-css output format, the ITextRenderer might just be able to cope with that better.

Another route might be to go to LaTeX. There are good LaTeX to pdf converters about. However, these can't deal with the rest of the html document.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM