我使用命令行:
pandoc input.org -o output.pdf --pdf-engine --variable CJKmainfont="Noto Sans SC" --variable mainfont="Noto Sans SC" --latext-engine=xelatex
可以正确的导出带有中文的 pdf 文件.
可是我在 org file 里面写文档参数:
#+pandoc_options: pdf-engine:xelatex
#+pandoc_options: “variable:mainfont=Noto Sans SC” “variable:CJKmainfont=Noto Sans SC”
导出的 pdf 文件是乱码
请问是哪里写错了呢? 谢谢
您可以试下导出 html 再用浏览器打印成 PDF。
可以用 org-html 导出成 html 再用 node+puppeteer 自动保存为 PDF。
这里分别是 nodejs 和 elisp 代码。
'use strict';
const puppeteer = require('puppeteer');
const [url, title] = process.argv.slice(-2,);
console.log('loading', title, url);
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.emulate(puppeteer.devices['iPad Pro landscape']);
await page.goto(url, { waitUntil: 'load' });
// page.pdf() is currently supported only in headless mode.
// @see https://bugs.chromium.org/p/chromium/issues/detail?id=753118
await page.setViewport({
width: await page.evaluate(() => document.body.clientWidth),
height: await page.evaluate(() => document.body.clientHeight)
});
await autoScroll(page);
await page.pdf({
path: './' + title + '.pdf',
format: 'A4',
scale: 0.75,
});
await browser.close();
console.log('finished', title + '.pdf');
})();
function autoScroll(page) {
return page.evaluate(() => {
return new Promise((resolve, reject) => {
var totalHeight = 0;
var distance = 100;
var timer = setInterval(() => {
var scrollHeight = document.body.scrollHeight;
window.scrollBy(0, distance);
totalHeight += distance;
if (totalHeight >= scrollHeight) {
clearInterval(timer);
resolve();
}
}, 150);
})
});
}
(defun org-html-export-to-pdf ()
"Export current buffer to a PDF file.
Using `org-html-export-to-html' and node-js puppeteer."
(interactive)
(let ((html-out (org-html-export-to-html))
(title (cadar (org-collect-keywords '("title")))))
(async-shell-command (concat "node ~/.spacemacs.d/scripts/html2pdf.js \"file://$PWD/" html-out "\" \"" title "\""))))
似乎应该是冒号,而不是等号。 PS:我没测试。
#+PANDOC_OPTIONS: "variable:CJKmainfont:Noto Sans CJK SC"