wshuyi / demo-batch-markdown-to-pdf

208 stars 52 forks source link

pandoc: 'XXX\temp_qiniu.md': openBinaryFile: invalid argument (Invalid argument) #2

Open hiei17 opened 5 years ago

juzha commented 4 years ago

Are you using Windows ? I have the same issue. Change ' to " fix the issue for me

Lodewijk-Eduard commented 2 years ago

which quotation marks are to be changed?

YSG-79 commented 12 months ago

here is the modified code. Note that there are two changes.

The first is "-V CJKmainfont=STSong", due to my system is windows. The second is "cmd = "pandoc \"{}\" -o \"{}\" --pdf-engine=xelatex -V CJKmainfont=STSong ".format(md_file, pdf_file)", change the '{}' to \"{}\" and delete the template order(because I don't care about the layout problem).

And I add a few debug code, neglect it. Also there are chinese annotations, I don't want to translate, neglect it again.

`from pathlib import Path import os

work_dir = Path.cwd()

export_pdf_dir = work_dir / 'pdf' if not export_pdf_dir.exists(): export_pdf_dir.mkdir()

for md_file in list(work_dir.glob('*.md')): md_file_name = md_file.name pdf_file_name = md_file_name.replace('.md', '.pdf') pdf_file = export_pdf_dir / pdf_file_name

STSong 或者 "STSong"是有效的,'STSong'是无效的,选择电脑内置的有效字体(通过命令fc-list :lang=zh查看)

cmd = "pandoc\ \"{}\\" -o\\"{}\\" --pdf-engine=xelatex -V CJKmainfont=STSong ".format(md_file, pdf_file)
result = os.system(cmd)
# 测试是否成功
if result != 0:
    print(f"fail!!")
else:
    print(f"success!!")`