Chuyển đến nội dung

Markdown sang PDF

Chuyển tệp .md sang PDF, giữ các tiêu đề thành mục lục.

Xử lý trên thiết bị của bạn

Công cụ này chạy hoàn toàn trong trình duyệt của bạn. Tệp của bạn không bao giờ được tải lên, và bạn có thể tự kiểm chứng điều đó trong tab mạng của trình duyệt. Tự kiểm chứng: mở tab mạng của trình duyệt và theo dõi. Bạn sẽ thấy một yêu cầu nhỏ hỏi xem bạn còn tác vụ nào không - một tên công cụ và một mã băm, không bao giờ là tệp.

Công cụ này làm gì

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.

Cách hoạt động

  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.

Công cụ này không làm được gì

  • 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.

Câu hỏi thường gặp

Công cụ hiểu biến thể Markdown nào?
CommonMark cộng thêm các phần mở rộng của GitHub: bảng, gạch ngang chữ, danh sách công việc và URL trần được biến thành liên kết. Tiêu đề, danh sách có thứ tự và không thứ tự, danh sách lồng nhau, trích dẫn khối, đường kẻ ngang, mã nội dòng và khối mã đều được xử lý. Phần front matter YAML ở đầu tệp được đọc làm tiêu đề tài liệu khi bật tuỳ chọn đó, thay vì được in ra thành một bảng.
Các tiêu đề của bạn có trở thành mục lục không?
Có. Khi bật "dấu trang từ tiêu đề", từ một dấu thăng đến sáu dấu thăng trở thành các mục trong mục lục PDF ở đúng cấp tương ứng, nên người đọc có một khung điều hướng được dựng từ chính cấu trúc sẵn có trong tệp của bạn. Không cần thêm gì vào Markdown và không cần chỉnh cho khớp bằng tay.
Vì sao hình ảnh trong Markdown của bạn bị thiếu?
Vì một tệp Markdown chỉ tham chiếu đến ảnh chứ không chứa chúng, và tải chúng về sẽ đồng nghĩa với việc trang này gửi một yêu cầu thay cho bạn - điều duy nhất mà mọi công cụ ở đây đều từ chối làm. Văn bản, bảng, danh sách, liên kết và mã đều được chuyển. Nếu hình ảnh quan trọng, hãy đưa chúng qua Ảnh sang PDF rồi ghép hai tài liệu bằng Gộp PDF.
Khối mã được trình bày thế nào?
Bằng Noto Sans Mono ở cỡ bằng 92 phần trăm cỡ chữ chính, trên nền màu nhạt, với tab được nới thành bốn dấu cách trước khi đo bất cứ điều gì. Một dòng rộng hơn cột được gập lại chứ không bị cắt, phần nối tiếp được thụt vào cho thẳng hàng với dòng gốc, và chỗ gập ưu tiên một dấu cách để một định danh dài không bị vỡ.
Tài liệu của bạn có bị tải lên để chuyển đổi không?
Không. Tệp được giải mã, phân tích và dàn trang trong một Web Worker bên trong trình duyệt của bạn, và tệp PDF cũng được tạo ngay tại đó. Thứ duy nhất mà trang này tải về là phông Noto từ chính máy chủ của trang, và một khi trình duyệt đã lưu nó vào bộ nhớ đệm thì việc chuyển đổi vẫn chạy được khi đã tắt kết nối.

Công cụ liên quan