问题描述
使用 wkhtmltox
转换带有 mathjax 的 HTML 网页文件,发现网页中的数学公式在 Chromium 浏览器中能正常显示,而在转换得到的 PDF 文档中无法显示。
我使用的转换命令是:
wkhtmltopdf test.html out.pdf
生成的 PDF 文档与原 HTML 文档对比如图:
请问怎样才能让 wkhtmltopdf 正确处理 HTML 文档中的 mathjax 数学公式,使其可以在生成的 PDF 文档中正常显示?
相关信息
- 操作系统:Linux Mint 21.1 Vera 64 位
- wkhtmltox 版本:0.12.6.1 r2
- wkhtmltox 来源:https://github.com/wkhtmltopdf/packaging/releases/tag/0.12.6.1-2
- Chromium 版本:108.0.5359.124
- 程序运行输出:
$ wkhtmltopdf --debug-javascript test.html out.pdf
Loading pages (1/6)
Warning: file:///home/user/test.html:11 SyntaxError: Parse error
Warning: https://gcore.jsdelivr.net/npm/[email protected]/es5/tex-chtml.js:1 SyntaxError: Parse error
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done
- 输入的 HTML 文档内容:
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>测试</title>
<script>
MathJax = {
options: {
renderActions: {
find: [10, function (doc) {
for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
const display = !!node.type.match(/; *mode=display/);
const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
const text = document.createTextNode('');
node.parentNode.replaceChild(text, node);
math.start = {node: text, delim: '', n: 0};
math.end = {node: text, delim: '', n: 0};
doc.math.push(math);
}
}, '']
}
}
};
</script>
<script type="text/javascript" src="https://gcore.jsdelivr.net/npm/[email protected]/es5/tex-chtml.js" async></script></head>
<body>
<h3 id="_1">测试</h3>
<p>
<script type="math/tex; mode=display">
e^x
</script>
</p>
</body>
</html>