Markdown 转 PDF:三种零成本方法
PDF 是最通用的“定稿”格式——发给谁都能看、排版不乱跳。下面三种方法都不需要付费软件。
Markdown 轉 PDF:三種零成本方法
PDF 是最通用的「定稿」格式——發給誰都能看、排版不亂跳。下面三種方法都不需要付費軟體。
Markdown to PDF: 3 Zero-Cost Methods
PDF is the most universal "final" format—anyone can open it and the layout never shifts. None of the three methods below needs paid software.
一、为什么先转 PDF
Markdown 本身是文本,发给别人未必有合适的预览工具;Word 又常被不同版本“改花”。PDF 是“所见即所得”的终稿:字体、分页、图片位置都锁死,最适合交作业、交报告、做文档归档。
二、方法一:浏览器直接打印(最快)
如果你在用在线编辑器,这是零安装的办法:
- 在 365Lab 编辑器 里写好内容,右侧就是渲染好的排版。
- 点顶栏“导入 / 导出”里的打印 / 存为 PDF。
- 在系统打印对话框里,把“目标打印机”选成“另存为 PDF”(Windows / Chrome / macOS 都内置)。
- 建议关掉“页眉页脚”里的网址,勾选“背景图形”以保留底色。
提示:深色主题也会被自动处理成浅色打印,不会打出黑底白字。
三、方法二:导出独立 HTML 再打印
想要更可控的版式(比如固定页边距、加封面),可以先导出一份自带样式的 HTML:
- 在编辑器“导出”菜单选导出 HTML(.html),得到一个不依赖网络的单文件。
- 双击用浏览器打开,再按
Ctrl / ⌘ + P另存为 PDF。 - 好处:HTML 里已内联全部样式,换台电脑打开排版也不变。
如果你想把同一份文档发到不同地方,先掌握基础语法 再配合这种导出最省事。
四、方法三:Pandoc 命令行
需要批量、自动化,或想要 LaTeX 级别的精细排版时,Pandoc 是开源首选:
# 安装(一次)
brew install pandoc # macOS
# 或: apt install pandoc # Linux
# 转换
pandoc 我的文档.md -o 我的文档.pdf
中文 PDF 建议再装一个中文字体引擎(如 TeX Live + xeCJK),否则可能缺字。命令行适合“一次配置、反复使用”的场景。
五、让排版更好看的 4 个细节
- 标题层级别跳级。从
#到##再到###,PDF 目录才清晰。 - 图片控制宽度。长图建议先压缩或外链,避免一页只塞下半个图。
- 用分割线分章。
---能天然形成视觉停顿,PDF 里也成立。 - 表格别太宽。列多了会让 PDF 横向溢出,必要时拆表或转成列表。
六、常见问题
Q:转出来的 PDF 是黑底怎么办?
A:多半是预览用了深色主题。导出前切回浅色,或用“导出 HTML”后在浅色浏览器里打印。
Q:中文乱码 / 缺字?
A:用浏览器打印通常没问题;命令行方式需确保装了中文字体。
Q:能批量转很多 .md 吗?
A:可以写一行循环:for f in *.md; do pandoc "$f" -o "${f%.md}.pdf"; done。
顺手复习一下 Markdown 表格写法,表格转 PDF 最容易出问题,提前避开。想做成可在阅读器里读的电子书,看 用 Markdown 写电子书 / EPUB。
一、為什麼先轉 PDF
Markdown 本身是文字,寄給別人未必有合適的預覽工具;Word 又常被不同版本「改花」。PDF 是「所見即所得」的終稿:字型、分頁、圖片位置都鎖死,最適合交作業、交報告、做文件歸檔。
二、方法一:瀏覽器直接列印(最快)
如果你在用線上編輯器,這是零安裝的辦法:
- 在 365Lab 編輯器 裡寫好內容,右側就是渲染好的排版。
- 點頂欄「匯入 / 匯出」裡的列印 / 存成 PDF。
- 在系統列印對話框裡,把「目標印表機」選成「另存為 PDF」(Windows / Chrome / macOS 都內建)。
- 建議關掉「頁首頁尾」裡的網址,勾選「背景圖形」以保留底色。
提示:深色主題也會被自動處理成淺色列印,不會印出黑底白字。
三、方法二:匯出獨立 HTML 再列印
想要更可控的版式(比如固定頁邊距、加封面),可以先匯出一份自帶樣式的 HTML:
- 在編輯器「匯出」選單選匯出 HTML(.html),得到一個不依賴網路的單檔。
- 雙擊用瀏覽器開啟,再按
Ctrl / ⌘ + P另存為 PDF。 - 好處:HTML 裡已內聯全部樣式,換台電腦開啟排版也不變。
如果你想把同一份文件發到不同地方,先掌握基礎語法 再配合這種匯出最省事。
四、方法三:Pandoc 命令列
需要批次、自動化,或想要 LaTeX 等級的精細排版時,Pandoc 是開源首選:
# 安裝(一次)
brew install pandoc # macOS
# 或: apt install pandoc # Linux
# 轉換
pandoc 我的文檔.md -o 我的文檔.pdf
中文 PDF 建議再裝一個中文字型引擎(如 TeX Live + xeCJK),否則可能缺字。命令列適合「一次設定、反覆使用」的場景。
五、讓排版更好看的 4 個細節
- 標題層級別跳級。從
#到##再到###,PDF 目錄才清晰。 - 圖片控制寬度。長圖建議先壓縮或外連,避免一頁只塞下半個圖。
- 用分隔線分章。
---能天然形成視覺停頓,PDF 裡也成立。 - 表格別太寬。欄多了會讓 PDF 橫向溢位,必要時拆表或轉成清單。
六、常見問題
Q:轉出來的 PDF 是黑底怎麼辦?
A:多半是預覽用了深色主題。匯出前切回淺色,或用「匯出 HTML」後在淺色瀏覽器裡列印。
Q:中文亂碼 / 缺字?
A:用瀏覽器列印通常沒問題;命令列方式需確保裝了中文字型。
Q:能批次轉很多 .md 嗎?
A:可以寫一行迴圈:for f in *.md; do pandoc "$f" -o "${f%.md}.pdf"; done。
順手複習一下 Markdown 表格寫法,表格轉 PDF 最容易出問題,提前避開。想做成可在閱讀器裡讀的電子書,看 用 Markdown 寫電子書 / EPUB。
1. Why convert to PDF first
Markdown is plain text; the person you send it to may not have a suitable previewer. Word files, meanwhile, often get "mangled" by different versions. A PDF is a what-you-see-is-what-you-get final copy: fonts, page breaks, and image positions are locked, making it ideal for homework, reports, and archival.
2. Method 1: Print straight from the browser (fastest)
If you're using an online editor, this needs zero installation:
- In the 365Lab editor, write your content—the rendered layout is already on the right.
- Click Print / Save as PDF in the top bar's "Import / Export" menu.
- In the system print dialog, set the destination printer to "Save as PDF" (built into Windows / Chrome / macOS).
- Turn off the URL in "Headers and footers", and check "Background graphics" to keep background colors.
Tip: A dark theme is automatically handled as a light print—you won't get black pages with white text.
3. Method 2: Export a standalone HTML, then print
For more control over layout (fixed margins, a cover page, etc.), export a self-contained styled HTML first:
- In the editor's Export menu, choose Export HTML (.html) to get a single file that doesn't depend on the network.
- Double-click to open it in a browser, then press
Ctrl / ⌘ + Pto save as PDF. - Bonus: the HTML has all styles inlined, so the layout stays identical on any other computer.
If you want to send the same document to different places, learn the basics first and this export pairs best.
4. Method 3: Pandoc from the command line
When you need batch processing, automation, or LaTeX-grade fine typesetting, Pandoc is the open-source go-to:
# Install (once)
brew install pandoc # macOS
# or: apt install pandoc # Linux
# Convert
pandoc my-doc.md -o my-doc.pdf
For Chinese PDFs, also install a Chinese font engine (e.g. TeX Live + xeCJK), or characters may be missing. The command line suits "set up once, reuse forever" scenarios.
5. Four details for better-looking output
- Don't skip heading levels. Go
#→##→###so the PDF outline stays clear. - Control image width. Compress or hotlink long images so a page doesn't end up half-filled by one picture.
- Split chapters with rules.
---creates a natural visual pause and works in PDFs too. - Don't let tables get too wide. Too many columns overflow sideways; split the table or turn it into a list when needed.
6. FAQ
Q: The exported PDF has a black background—what do I do?
A: It's usually because the preview used a dark theme. Switch back to light before exporting, or export HTML and print from a light-themed browser.
Q: Chinese characters show as garbled / missing?
A: Browser printing is usually fine; for the command-line route, make sure a Chinese font is installed.
Q: Can I batch-convert many .md files?
A: Yes—one loop does it: for f in *.md; do pandoc "$f" -o "${f%.md}.pdf"; done.
While you're here, review how to write Markdown tables—tables cause the most PDF trouble, so avoid issues early. To make an e-book readable in a reader, see Writing e-books / EPUB in Markdown.