离线 · 无上传 · 浏览器本地完成Offline · no uploads · runs in the browser
TXT 转 JPG——离线、按 A4 分页、中间过一份 PDFTXT to JPG offline — A4 pages, via a PDF
这条路和 TXT→PNG 不是一回事,差别在**中间那份 PDF**:`txt>html` + `html>pdf` + `pdf>jpg`(三步,路径基线现读)。第一步把纯文本包成等宽 `<pre>` 的网页;第二步由 `html-raster` 在**固定 800 px 版心**里排版(`utils/core/html-raster.ts:7` 的 `RENDER_WIDTH`),把整页渲染成一张画布,再由 `html>pdf` **按 210 mm 宽把这张画布等比映射到 A4 纵向、每 297 mm 切一刀**(800 px 宽下约每 1131 px 排版高度一页),逐页作为 **PNG 无损切片**写进那份临时 PDF;第三步由 pdf.js 把每一页画到**白底画布**上,编成 JPEG。于是几件事同时成立:**产出是一页一张的纸**,不是一张连续长图;**整条链只量化一次**(中间是 PNG 切片,质量参数只作用在终点);背景是白的(渲染器写死 `backgroundColor` 为白色,所以文字图没有透明通道可言);**页数决定容器**——只有一页时产物是 `converted.jpg`,两页以上打包成 `converted.zip`,成员按文档页码命名(`page-3.jpg` 就是那份 PDF 的第 3 页)。要如实说的代价有两条,都和「看不看得见」有关:一,`<pre>` **不折行**——800 px 版心里它只剩 **702 px 的文字区**(800 减去 body 左右内边距 64、再减去 `pre` 自己的边框 2 与内边距 32,这几个数都是 `utils/core/html-document.ts` 里写死的 CSS),而 `pre` 是 `overflow-x: auto`:超出的行尾既不会被挪到下一行、也不会画进图里,宽度方向没有任何检查会报错;二,高度有闸——整页排到 32768 px 上限时渲染那一步明确报错(`errors.renderTooTall`),而不是给你半份图,所以超长文本请先拆短;同一道高度闸也让这份中间 PDF 实际排不到几百页,出图那一步的页数上限在这条链上碰不到。图里的字仍是像素:选不中、搜不到,要能被复制就留在 TXT / Markdown / HTML。全程只有 storage 权限,不联网。This is not the same route as TXT to PNG, and the difference is **the PDF in the middle**: `txt>html` + `html>pdf` + `pdf>jpg` — three steps, read live from the baseline. Step one wraps the text as a monospace `<pre>` page. Step two lays it out inside a **fixed 800 px measure** (`RENDER_WIDTH` at `utils/core/html-raster.ts:7`), renders the whole page to one canvas, and then `html>pdf` **maps that canvas onto A4 portrait at 210 mm wide and cuts every 297 mm** — at 800 px that is roughly one sheet per 1131 px of laid-out height — writing each slice into the temporary PDF as a **lossless PNG**. Step three has pdf.js draw every page onto a **white canvas** and encode it as JPEG. Four things hold at once: the output is **one sheet per page**, not a single continuous image; **the chain quantises only once** (the middle is PNG slices, and the quality knob acts on the endpoint); the ground is white, because the renderer pins `backgroundColor` to white, so there is no alpha to speak of in a text picture; and **the page count decides the container** — a single page comes out as `converted.jpg`, two or more are packed into `converted.zip` with members named after the document page, so `page-3.jpg` is page 3 of that PDF. Two costs have to be said plainly, both about what you can see. First, `<pre>` **does not wrap**: inside the 800 px measure it keeps only a **702 px text band** (take the body’s 64 px of horizontal padding, then the `pre`’s own 2 px of border and 32 px of padding off that measure — all four numbers are hard-coded CSS in `utils/core/html-document.ts`), and because the `pre` is `overflow-x: auto`, what runs past that is neither moved to a next line nor painted into the picture, with nothing on the width axis raising an error. Second, height is gated: past 32768 px of laid-out page the render step fails with `errors.renderTooTall` instead of handing you half a document, so split long text first — and that same ceiling is why the intermediate PDF never grows to hundreds of pages, which in turn means the image step’s page cap is unreachable on this chain. The words in the image are still pixels: unselectable and unsearchable, so stay in TXT, Markdown or HTML when text must be copied. All of it on the storage permission, with no network.
这条链路怎么走How the route runs
纯文本 (TXT)plain text (TXT) HTMLHTML PDFPDF JPEGJPEG
共 3 步,由扩展的路径搜索自动选出,中间产物不落盘。3 steps, chosen by the extension's own path search; intermediate results never touch the disk.
会保留什么What carries over
- 一页一张的纸:按 A4 切页,不是一张连续长图(这是与 TXT→PNG 的实际分界)One sheet per page, sliced on A4 — not a single continuous image, which is the real dividing line with TXT to PNG
- 页数决定容器:单页给 `converted.jpg`,两页以上打包成 `converted.zip`,成员按页码命名 `page-N.jpg`The page count picks the container: one page comes back as `converted.jpg`, two or more are zipped as `converted.zip` with members named `page-N.jpg`
- 整条链只量化一次:中间是 PNG 无损切片,质量与目标尺寸只作用在 JPEG 终点The chain quantises once: the middle is lossless PNG slices, and quality plus target size act only on the JPEG endpoint
- 背景固定白底:文字图不会有透明通道,也不会有半透明边缘A fixed white ground: a text picture gets no alpha channel and no semi-transparent edges
- 高度有闸:超过 32768 px 明确报 `errors.renderTooTall`,不静默给你半份图Height is gated: past 32768 px the render step fails with `errors.renderTooTall` rather than returning half a document
- 一批最多 200 个文件、单个 100 MB,与其他路线共用同一道闸门Up to 200 files per batch and 100 MB each — the same gate every other route shares
如实说明的限制What it does not do
- `<pre>` 不折行:800 px 版心里它只剩 702 px 文字区(扣掉 body 64、边框 2、内边距 32),且 `overflow-x: auto`——超出的行尾不换行也不会画进图里,请先拆短长行`<pre>` never wraps: the text band is 702 px inside the 800 px measure (the body’s 64, its own 2 of border and 32 of padding come off) and it is `overflow-x: auto`, so line ends past it are neither reflowed nor painted — break long lines first
- 产物是图片:字选不中、搜不到,屏幕阅读器也读不出来The artifact is an image: words cannot be selected, searched or read aloud
- 有损终点:文字边缘正是 JPEG 最先出振铃的地方,要归档或再取字请走 PNG 或留在文本A lossy endpoint: glyph edges are exactly where JPEG ringing appears first, so use PNG or plain text for archival and for retrievable words
- 超长受 32768 px 高度上限约束,TXT→PDF 用同一道闸,绕不开Very long text hits the 32768 px height ceiling, and TXT to PDF shares that same gate — there is no way around it here
- 没有页码选择这一步:它的分页来自排版,源文件是 PDF 时才有那份选页参数There is no page-range step: pagination comes from layout, and the range control exists only when the source is a PDF
实操提示Working with it
- 要一张连续长图:TXT→PNG,两步不经 PDFFor one continuous image: TXT to PNG, two steps with no PDF inside
- 要一份多页文档:TXT→PDF,中间那份 PDF 就是终点、PNG 切片无损For a multi-page document: TXT to PDF, where that intermediate PDF becomes the destination
- 要体积更小的分页快照:TXT→WebP 是同一条三步链,终点换成 WebPFor a smaller paginated snapshot: TXT to WebP is the same three-step chain with WebP at the end
常见问题Questions people actually ask
为什么我的长行右边少了几个字?Why did the right end of my long lines go missing?
因为这条链的排版版心固定 800 px(`html-raster` 的 `RENDER_WIDTH`),而 `<pre>` 不折行——它在版心里只剩 702 px 的文字区(扣掉 body 左右内边距 64、`pre` 边框 2 与内边距 32,四个数都写死在 `utils/core/html-document.ts`),又是 `overflow-x: auto`,所以超出的行尾既不换行也不会被画进图里,宽度方向没有任何检查会提示你。要么先把行拆短,要么改用会横向滚动的载体(HTML),要么走 TXT→PDF 自己在阅读器里看。另外记一句:两页以上时你拿到的是一个 ZIP,每页一张 `page-N.jpg`。Because this chain lays out at a fixed 800 px measure (`RENDER_WIDTH` in `html-raster`) and `<pre>` does not wrap: inside that measure it keeps a 702 px text band (the body’s 64 px of horizontal padding, its own 2 px of border and 32 px of padding all come off — the four numbers are hard-coded in `utils/core/html-document.ts`), and since it is `overflow-x: auto`, characters past it are neither moved down a line nor painted into the picture, with nothing on the width axis warning you. Break long lines first, use a carrier that scrolls sideways (HTML), or take TXT to PDF and read it in a viewer. One more thing to note: from two pages upwards what you get is a ZIP, one `page-N.jpg` per sheet.
和 TXT→PNG 该选哪个?Should I take TXT to JPG or TXT to PNG?
看你要「纸」还是要「原样」。TXT→PNG 是两步、不套 PDF,产出一张连续长图且无损;TXT→JPG 多一道 PDF 中间产物,按 A4 切成一页一张,终点有损。要贴进只收图片的地方且控制体积就选 JPG,要保持边缘锐利或之后再取字就选 PNG。Decide whether you want paper or the original. TXT to PNG is two steps with no PDF inside, one lossless continuous image; TXT to JPG adds a PDF in the middle, slices onto A4 one page per image and quantises at the end. Pick JPG where a picture is all the destination accepts and size matters, PNG when edges must stay crisp or the words may be needed later.
很长的日志能一次转完吗?Can I convert a very long log in one go?
不能,而且两条路都拦你:排版高度超过 32768 px 时渲染那一步会明确报错,让你拆短分批——TXT→PDF 用的是同一个渲染器与同一道上限,绕不过去。这条链的中间 PDF 也因此排不到几百页,所以出图那一步的页数上限在这条路上其实碰不到。No, and both routes stop you: past 32768 px of laid-out height the render step fails and asks you to split the text — TXT to PDF uses the same renderer and the same ceiling, so there is no way around it. The intermediate PDF therefore never grows to hundreds of pages either, which is why the image step’s page cap is unreachable on this chain.
不需要账号,也不需要联网:装好扩展后点图标,在新标签页里打开工作台,文件从磁盘直接选。No account and no network: install the extension, click its icon, and the workbench opens in a new tab reading straight off your disk.
从 Chrome 应用商店安装Install from the Chrome Web Store 安装步骤Install steps GitHub 源码Source on GitHub
要把它压到指定体积?Need it under a target size? The 图片压缩工具image compressor可以在浏览器里重编码 PNG / JPEG / WebP。 re-encodes PNG / JPEG / WebP in the browser.