跳到正文

Markdown 转 PDF

把 .md 文件转换为 PDF,标题保留为书签大纲。

在你的设备上处理

这款工具完全在你的浏览器中运行。文件从不上传,你可以在浏览器的网络标签中亲自验证这一点。 亲自验证:打开浏览器的网络标签观察。你会看到一个查询你是否还有剩余任务的小请求,只包含工具名称和一段哈希,绝不会包含文件。

这款工具的作用

This reads a Markdown file and lays it out as a PDF directly, without going through HTML on the way. Headings, lists, tables, block quotes, links and fenced code blocks all come across, and the headings also become a real PDF outline. Markdown has no pages of its own, so the pagination is created here rather than reproduced from anywhere - the paper size, margins and theme you pick are what decide where the breaks fall.

Use it when the reader has no Markdown reader: a README that has to go into a tender pack, meeting notes an editor wants as an attachment, a specification circulating for comment, or documentation you want on paper with a table of contents that works.

工作原理

  1. Drop your .md or .markdown files onto this page. Up to 20 at a time, each up to 50 MB.
  2. Pick a theme. Plain sets 11 pt with 1.45 line spacing, Book loosens to 11.5 pt and 1.6 for something read end to end, and Technical tightens to 10 pt and 1.35 for reference material that gets scanned rather than read.
  3. Choose the paper size, orientation and margins. Normal margins are 56 points on every side.
  4. Leave bookmarks from headings on so the finished PDF opens with a working outline, and turn page numbers off if the document already numbers itself.
  5. Under advanced options, decide whether YAML front matter at the top of the file should supply the document title.
  6. Press Convert. Each file becomes its own PDF and the downloads start on their own.

The parser walks Markdown into the document model directly and never renders it to HTML first. That sounds like an implementation detail and is not: a Markdown-to-HTML-to-PDF route escapes the content twice, and every escaping bug in that round trip shows up later as a stray ampersand or a visible line-break tag in somebody's finished document. Going straight to the model means the text you wrote is the text that gets measured.

Headings become the PDF outline, which is the thing that makes a long Markdown document usable as a PDF at all. A forty-page specification without an outline is a scroll bar and nothing else. One hash through six become outline entries at the matching depth, so the structure you already have in the file is the navigation the reader gets, with no extra step and nothing to maintain separately.

GitHub-flavoured extensions are on, so tables, strikethrough, task lists and bare URLs behave the way they do on GitHub rather than being left as literal punctuation. Fenced code blocks are set in Noto Sans Mono at 92 per cent of the body size, on a tinted wash, and a block longer than the remaining space is split across pages with the wash redrawn rather than being pushed whole onto the next sheet. Long code lines are folded, with the continuation indented to match the line it came from and the break preferred at a space so an identifier is not cut in half.

Images referenced by the Markdown are not embedded, and raw HTML blocks are not rendered. A Markdown file points at its pictures by path or by URL rather than containing them, and going out to fetch one would be exactly the outbound request this tool exists not to make. Convert the pictures separately with Images to PDF and join the results with Merge PDF if they need to be in the same document.

The Book theme asks for a serif face, and it is worth knowing what that gets you. With Embed a Unicode font on, which is the default, there is no Noto Serif in the embedded set, so serif borrows the sans faces and what you actually gain is the looser leading and the larger type. Turn embedding off and the text really is set in Times Roman, at the cost of every character outside the WinAnsi range.

这款工具做不到的事

  • Images referenced by the Markdown are not embedded. Fetching them would mean an outbound request; convert them with Images to PDF and combine the results instead.
  • Raw HTML inside the Markdown is not rendered. Structure written as Markdown converts; structure written as HTML tags does not.

常见问题

它理解哪种 Markdown 方言?
CommonMark 加上 GitHub 扩展:表格、删除线、任务列表,以及会变成链接的裸网址。标题、有序和无序列表、嵌套列表、块引用、水平分隔线、行内代码和围栏代码块全部都能处理。文件顶部的 YAML front matter,在开启相应选项时会被读作文档标题,而不是作为一个表格打印出来。
我的标题会变成目录吗?
会。开启「从标题生成书签」后,一个到六个井号会成为对应层级的 PDF 书签条目,于是读者会得到一个由你文件中已有结构生成的导航面板。无需往 Markdown 里添加任何东西,也无需手动保持同步。
为什么我的 Markdown 里的图片不见了?
因为 Markdown 文件是引用它的图片,而不是包含它们,而去获取它们就意味着这个页面替你发出请求——而那正是这里每款工具都拒绝做的事。文本、表格、列表、链接和代码全部都会转换。如果图片很重要,就用「图片转 PDF」处理它们,再用「合并 PDF」把两个文档拼到一起。
围栏代码块是怎样排版的?
以 Noto Sans Mono、正文字号的 92% 排版,衬在一层浅色底纹上,并在测量之前把制表符展开为四个空格。比栏宽还宽的行会被折行而不是截断,续行会缩进到与它所在的那一行对齐,而且折行优先选在空格处,好让一个长标识符保持完整。
转换时我的文档会被上传吗?
不会。文件在你浏览器内的 Web Worker 中解码、解析和排版,PDF 也在那里生成。这个页面唯一会去获取的东西是来自本站点自己源的 Noto 字体,一旦你的浏览器缓存了它,转换在断网时也能进行。

相关工具