- Windows 下安裝 Pandoc
-
pandoc -v查看版本
pdf 轉(zhuǎn)換為 docx
中文轉(zhuǎn)換時(shí)的亂碼
通過(guò) -V 參數(shù)指定中文字體
-V mainfont="Microsoft YaHei"
如果還是不行,請(qǐng)?jiān)囋囕斎耄?/p>
-V CJKmainfont=KaiTi
注意:-V 是 --variable 的縮寫(xiě)。
其他格式的文件轉(zhuǎn)化為 docx
-
Word docx:
pandoc -s MANUAL.txt -o example29.docx -
LaTeX math to docx:
pandoc -s math.tex -o example30.docx -
Markdown to docx:
pandoc -s m.md -o m.docx -
Docx with a reference docx:
pandoc --reference-doc twocolumns.docx -o UsersGuide.docx MANUAL.txt
解決中文亂碼
pandoc -V mainfont="Microsoft YaHei" --reference-doc twocolumns.docx -o UsersGuide.docx MANUAL.txt
這里是以 twocolumns.docx 為模板將 MANUAL.txt 寫(xiě)入到 UsersGuide.docx,使得UsersGuide.docx 和 twocolumns.docx 具有相同的格式。
更多內(nèi)容參考:Pandoc Demos
其他
Docx to markdown, including math:
pandoc -s example30.docx -t markdown -o example35.md
EPUB to plain text:
pandoc MANUAL.epub -t plain -o example36.text
If no input-files are specified, input is read from stdin. Output goes to stdout by default. For output to a file, use the -o option:
pandoc -o output.html input.txt
By default, pandoc produces a document fragment. To produce a standalone document (e.g. a valid HTML file including <head> and <body>), use the -s or -- standalone flag:
pandoc -s -o output.html input.txt
Character encoding
Pandoc uses the UTF-8 character encoding for both input and output. If your local character encoding is not UTF-8, you should pipe input and output through iconv:
iconv -t utf-8 input.txt | pandoc | iconv -f utf-8
Note that in some output formats (such as HTML, LaTeX, ConTeXt, RTF, OPML, DocBook, and Texinfo), information about the character encoding is included in the document header, which will only be included if you use the -s/--standalone option.
vscode 中的 pandoc
在 Markdown 開(kāi)頭的位置添加如下內(nèi)容:
---
title: "文檔"
author: XXXX
date: 2019/8/22
output:
word_document:
toc: true
reference_doc: demo.docx
---
便可以直接將 .md 文檔轉(zhuǎn)換為以 demo.docx 為模板的 .docx 文檔。在 Markdown 的預(yù)覽區(qū)域,鼠標(biāo)右鍵選擇 Pandoc:

總結(jié):
- markdown 轉(zhuǎn)換為 html:
pandoc README.md -o README.html - Markdown 轉(zhuǎn) word:
pandoc README.md -o README.docx - markdown 轉(zhuǎn)換為 pdf:
pandoc README.md -o README.pdf --pdf-engine=xelatex(latex之前是雙短橫線)- 在執(zhí)行本條命令之前,需要首先安裝 latex 編譯器,對(duì)于 windows 用戶,比如安裝 ctex 安裝組件;
-
pandoc -s C.docx -t markdown -o C.md:可以將 docx 轉(zhuǎn)換為 markdown - 各種例子
參考資料: