PDF 转 Markdown
把 PDF 转成 Markdown,还原其中的标题、列表和表格。
这款工具完全在你的浏览器中运行。文件从不上传,你可以在浏览器的网络标签中亲自验证这一点。 亲自验证:打开浏览器的网络标签观察。你会看到一个查询你是否还有剩余任务的小请求,只包含工具名称和一段哈希,绝不会包含文件。
这款工具的作用
This reads a PDF's text and writes it out as Markdown, working out which lines are headings, where paragraphs begin and end, and which blocks are lists or tables. A PDF stores none of that - only characters at coordinates - so the structure is inferred from geometry, except where the document has a bookmark outline, which is used instead because it is the author's own account of the structure. The result is one .md file that re-flows; it does not reproduce the original pagination or layout.
Reach for it when a document has to become editable text again: a report going into a wiki, documentation that arrived as a PDF and now needs to live in a repository beside the code, or notes you would rather search and rewrite than scroll through.
工作原理
- Drop the PDF onto this page. The first five pages are checked for a text layer, so a scan is caught before you download an empty file.
- Leave Use the bookmark outline on when the document has one. A real outline is more reliable than any guess made from type size.
- Choose what else to detect: headings where no bookmark covers them, lists, and tables written as Markdown pipe tables.
- Under advanced options, add a front matter block if the file is headed for a static site, and set a page range if you only want part of the document.
- Press Convert to Markdown. The .md file downloads on its own.
A line becomes a heading when it is set larger than the body text around it, is short, and is followed by prose - three conditions rather than one, because any of them alone promotes running heads and figure captions by mistake. Bookmarks override the lot, which is why a document with a proper outline converts noticeably better than one without.
Paragraphs are rebuilt by asking why each line ended. A line that runs to the right edge of its column was broken by the typesetter, so the next line is joined onto it; a line that stops short ended on purpose, so a new paragraph starts. Hyphens at a line end are rejoined only when the continuation begins with a lowercase letter, which is what stops Coca- and Cola being welded into a word that was never in the document.
Tables are the least certain part of the conversion. Column boundaries are found by clustering the horizontal positions of text runs, so a real table converts cleanly while a two-column page layout can occasionally be read as one.
Extraction runs through PDF.js in a Web Worker inside your browser. What would be uploaded here is the document's text, which is usually the confidential part. Nothing about the text is sent, and the one request a run makes asks whether you have tasks left - a tool name and a hash of the bytes.
这款工具做不到的事
- Images are not extracted. The output is text and structure only; if you want the pages as pictures, PDF to image is the tool for that.
- Layout is not preserved. Columns, text boxes and absolute positioning collapse into a single reading order, which is what Markdown is for and what makes it re-flow.
常见问题
- 它怎么判断哪些是标题?
- 如果 PDF 有书签大纲,就用这些书签作为标题,书签的层级即标题级别,完全不靠猜测。若没有大纲,当一行比周围正文更大、更短、且后面接着普通正文时,才会被提升为标题。这两个来源各有独立的开关。
- 表格会被转换吗?
- 会,只要检测器对列的判断足够有把握,就会写成 Markdown 管道表格。位置是从文字的左右两端聚类得出的,所以右对齐的数字列和左对齐的列一样都能找到。如果这些数字要放进电子表格,用 PDF 转 CSV 更合适。
- 文档里的图片会怎么样?
- 会被留下。Markdown 只是引用图片而不包含它们,要带上就得在 .md 旁边写出一整个图片文件夹。这个转换改为生成一个自包含的单一文本文件。
- 我的 PDF 是扫描件,什么都出不来。为什么?
- 扫描页是文字的照片:没有可供转换器读取的字符,所以工具会停下来给出说明,而不是写出一个空文档。请先运行 OCR 文字识别,再来转换。
- 转换时我的文档会被上传吗?
- 不会。文字在你的浏览器里提取,Markdown 也在那里写出,全程没有任何对外请求。你不必凭信任接受:转换时看着网络标签,或者干脆断网再转一次。