【问题标题】:Math equations support in xhtml to pdf conversion in Java数学方程支持 xhtml 到 Java 中的 pdf 转换
【发布时间】:2017-05-29 12:26:13
【问题描述】:

我正在尝试使用 ItextRenderer 将我的 xhtml 代码转换为 pdf,但问题是数学方程式没有很好地转换。我正在使用 mathjax 在所有浏览器中查看方程式:

<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"/>

这是我的html代码:

<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>

html pdf 转换器代码是这样的:

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();

问题在于,在 pdf 中,除了方程之外的所有工作。这是 pdf 中的方程 Equation in pdf

有没有办法在 pdf 中应用函数?或者在 Java 中应用其他方式?谢谢!

【问题讨论】:

    标签: java html pdf math mathjax


    【解决方案1】:

    您也许可以更改MathJax output formats。您可以使其生成 SVG 输出,而不是生成 xhtml。也可能值得尝试 HTML-css 输出格式,ITextRenderer 可能会更好地处理它。

    另一条路线可能是去 LaTeX。有很好的 LaTeX 到 pdf 转换器。但是,这些无法处理 html 文档的其余部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-21
      • 1970-01-01
      • 1970-01-01
      • 2016-02-25
      • 2013-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多