文本转 PDF
把 .txt、.log 或 .csv 排成 PDF 清单。
这款工具完全在你的浏览器中运行。文件从不上传,你可以在浏览器的网络标签中亲自验证这一点。 亲自验证:打开浏览器的网络标签观察。你会看到一个查询你是否还有剩余任务的小请求,只包含工具名称和一段哈希,绝不会包含文件。
这款工具的作用
This sets a plain text file as a PDF, one line of the file to one line of the page. The defaults are those of a code listing rather than a letter - monospace, 10 pt, wrapping on - because almost nobody converts prose this way. People convert a log, a configuration file, a CSV or a source file, usually because something else insists on receiving it as an attachment or a printout.
Reach for it when a text file has to travel as a document: a log going onto a support ticket, a configuration file that has to sit in a change record, a CSV a colleague wants to read rather than open in a spreadsheet, or a source file heading for someone with nothing to open it in.
工作原理
- Drop your .txt, .log, .csv or .md files onto this page. Up to 50 at a time, each up to 50 MB.
- Choose the typeface. Monospace is the default and is what keeps the columns of a log or a CSV lined up; sans and serif are there for the rare file that is actually prose.
- Set the type size and line spacing. 10 pt is the default; 8 pt fits noticeably more on a sheet and is worth it for a long log.
- Decide about long lines. Wrapping folds anything wider than the column so it stays visible; with wrapping off, an over-long line is clipped at the page edge instead, which is the honest rendering of a file whose lines are meant to be lines.
- Turn on line numbers if you expect to refer to a particular line, then press Convert.
- Each file downloads as its own PDF.
Wrapping is the one option that changes what the document means, which is why it is offered rather than decided for you. A folded long line stays readable but stops being one line, and anyone counting lines or diffing the output against the original will notice. An unwrapped line is truthful about the file and runs off the sheet. Both are right sometimes: wrap a log you want to read, leave it unwrapped for a file where line boundaries carry meaning.
When wrapping is on, the fold is done carefully. Tabs are expanded to four spaces before anything is measured, the continuation is indented to match the leading whitespace of the line it came from, and the break is preferred at a space so a long path or identifier is not cut in half mid-word. The number of characters that fit is worked out from the actual width of a monospace digit at your chosen size, not guessed.
Line numbers are padded to the width of the largest number in the file and followed by two spaces, so they form a straight column and the text stays aligned all the way down. They are drawn as part of the text rather than in a margin, which means they come with you when you copy a line out of the finished PDF. That is what you want when quoting a line to somebody, and not what you want if you are going to paste the listing back into an editor.
The file is decoded as UTF-8, and a byte-order mark at the start is stripped - a BOM is a mark, not a character, and left in place it renders as an invisible-width glyph at the top of the first page in some viewers. Bytes that are not valid UTF-8 become the replacement character rather than aborting the conversion, so a file saved in an older Windows or Japanese encoding will convert but will show damage where the accented characters were. Windows, Unix and classic Mac line endings are all recognised as breaks.
The embedded font is Noto Sans Mono or Noto Sans, subsetted to the characters your file actually uses, which is what keeps a converted log at tens of kilobytes rather than megabytes. It does not cover Chinese, Japanese, Korean, Arabic or Indic scripts. Turning embedding off falls back to Courier, Helvetica and Times, which are WinAnsi only, and there a replacement character comes out as a question mark.
这款工具做不到的事
- Chinese, Japanese, Korean, Arabic and Indic scripts are outside the embedded font's coverage, because the faces that would cover them are tens of megabytes each.
常见问题
- 对于超出页面宽度的行会怎么处理?
- 开启折行时,它们会折到下一行,缩进到与原行开始处对齐,并在有空格的地方断开。关闭折行时,它们会在页面边缘被截断,于是你看到的是文件每一行对应页面一行,而很长的行的远端根本不会显示出来。当行的边界重要时把它关掉,当可读性重要时把它开启。
- 为什么默认是等宽字体?
- 因为等宽字体是唯一能让列保持对齐的字体,而人们在这里转换的大多是列状内容:左侧带时间戳的日志、CSV、配置文件、带缩进的源代码。用比例字体的话,那些列在几行之内就会错开。对于偶尔真的是散文的文件,也提供了无衬线和衬线字体。
- 我的重音字符变成了奇怪的符号。为什么?
- 文件按 UTF-8 解码。如果它是用较旧的单字节编码(如 Windows-1252)或某种日文编码保存的,那么重音字符的字节就不是有效的 UTF-8,会被替换掉,而不是去猜测。请在你的编辑器里把文件重新保存为 UTF-8 再转换。字节顺序标记(BOM)如果有的话会被自动去掉。
- 我能一次转换多个文件吗?
- 可以,一次最多 50 个,每个都会生成自己的 PDF,以源文件命名。页面设置、字号、折行和行号设置对所有文件都适用,所以一整个文件夹的日志出来会保持一致。文件名字段只在你转换单个文件时才起作用。
- 我的文件会被上传吗?
- 不会。这些字节在你浏览器内的 Web Worker 中解码和排版,PDF 也在那里生成。这个页面发出的唯一请求是获取来自本站点自己源的 Noto 字体,而且只有在开启 Unicode 嵌入时才会。如果你宁愿核实而不是听我们说,就打开浏览器的网络标签并转换点东西。