markdown 转 docx 及 pdf 转 docx

pdf 转换为 docx

中文转换时的乱码

通过 -V 参数指定中文字体

-V mainfont="Microsoft YaHei"

如果还是不行,请试试输入:

-V CJKmainfont=KaiTi

注意:-V--variable 的缩写。

其他格式的文件转化为 docx

  1. Word docx:

    pandoc -s MANUAL.txt -o example29.docx
    
  2. LaTeX math to docx:

    pandoc -s math.tex -o example30.docx
    
  3. Markdown to docx:

    pandoc -s m.md -o m.docx
    
  4. 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 写入到 UsersGuide.docx,使得UsersGuide.docxtwocolumns.docx 具有相同的格式。
更多内容参考: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 开头的位置添加如下内容:

---
title: "文档"
author: XXXX
date: 2019/8/22
output:
  word_document:
    toc: true
    reference_doc: demo.docx
---

便可以直接将 .md 文档转换为以 demo.docx 为模板的 .docx 文档。在 Markdown 的预览区域,鼠标右键选择 Pandoc

总结:

  • markdown 转换为 html:pandoc README.md -o README.html
  • Markdown 转 word:pandoc README.md -o README.docx
  • markdown 转换为 pdf:pandoc README.md -o README.pdf --pdf-engine=xelatex(latex之前是双短横线)
    • 在执行本条命令之前,需要首先安装 latex 编译器,对于 windows 用户,比如安装 ctex 安装组件;
  • pandoc -s C.docx -t markdown -o C.md:可以将 docx 转换为 markdown
  • 各种例子

参考资料:

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
禁止转载,如需转载请通过简信或评论联系作者。

推荐阅读更多精彩内容

  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 2,727评论 0 3
  • 明显已经过了愤青的年纪,不时会指着一脸正义愤怒呐喊的忧国忧民分子调侃地说“看,愤青”,轻佻地像“看,灰机”一样。也...
    李子李子短信阅读 653评论 0 8
  • 本文主要讲述golang的gui库andlabs/ui使用。目前该库还不是很完善。 环境说明: 系统:Win10 ...
    小墨马阅读 8,316评论 4 52
  • ——挑战自己,改变自己,感恩有你 20171215 褚旭践行自己承诺90天记录(35/90) [奋斗]未来90天,...
    褚洪嘉阅读 326评论 0 0
  • 杯空,人走,独自之时。望着窗外的景致,似曾产生的情感,想着如何同你道来。 偷得这一番空闲,从前会多感谢:喝...
    悄吟绵亘_阅读 310评论 0 0