跳到正文

线性化 PDF

重排文件顺序,让第一页在其余内容到达之前就显示出来。

在你的设备上处理

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

这款工具的作用

A linearised PDF is the same document with its objects in a different order. Everything the first page needs is moved to the front of the file, so a reader can draw page one while the remaining megabytes are still arriving. Nothing about the pages, the text or the images changes - open the result next to the original and you will not be able to tell them apart on screen.

Do it to any PDF you publish on a website, link to in an email, or hand to a viewer embedded in an app. It matters most for large files on slow connections, where a document that opens in two seconds and one that appears to hang for thirty are the same file in two different orders.

工作原理

  1. Drop the PDF onto this page. Files up to 300 MB are accepted.
  2. Leave Also repack the file on. It recompresses the streams first, which usually takes another 10 to 25 per cent off the size.
  3. Press Linearize.
  4. The download starts on its own, with a -web suffix so you can tell the two versions apart.
  5. Upload the result as it is. No setting is needed to produce the effect, though your server must support byte-range requests for readers to use it.

The mechanism is ordering, not compression. In an ordinary PDF the objects sit wherever the producer wrote them and the index that finds them is at the end, so a reader over HTTP either waits for the whole file or asks for pieces of it in several round trips. Linearising puts a small hint table, the first page and every object that page depends on right at the front, followed by the rest in page order.

Repacking and linearising pull against each other, which is why the order of the passes matters. Object streams make a file smaller by packing many objects into one compressed block, and linearisation needs the first page's objects reachable on their own. The repack runs first and the linearisation last, so qpdf resolves the conflict rather than producing a file that claims to be linearised and is not.

The effect only exists if the server cooperates. Fast Web View depends on HTTP byte-range requests: the reader asks for the first part of the file, draws page one, then asks for more. A server that does not honour ranges sends the whole file regardless, and the linearised document behaves like the ordinary one. Most static hosting and every CDN supports ranges; some application frameworks streaming a file through their own handler do not.

If the repack fails on an unusual file, you still get the linearisation you asked for. Recompression is treated as a bonus rather than a requirement.

The job happens in your browser through qpdf compiled to WebAssembly, so the file you are preparing to publish - often still a draft - reaches no server before you put it on one.

这款工具做不到的事

  • The benefit only appears when the file is served over HTTP by a server that supports byte-range requests. Opening a linearised file from disk is no faster.

常见问题

线性化到底对文件做了什么?
它把同样的内容用不同的顺序重写:提示表和第一页所需的一切放到最前面,其余按页码顺序跟在后面。页面、图像、文字都不会改变。由于一些对象不能再共用一个压缩块,文件通常会比完全打包的版本稍大一点。
只用邮件发送的文件也需要这个吗?
不需要。快速 Web 查看只有在阅读器通过 HTTP 一点点获取文档时才有用。附件在打开前就已经整份下载完毕,所以线性化对它没有任何影响。它适合你自己发布、嵌入或链接出去的文件。
文件会变大还是变小?
两种效果都在起作用。线性化会加上一张提示表,并让一些对象无法打包在一起,所以会略微增大。可选的「重新打包」会重新压缩所有流,对没优化过的文件通常能减少 10 到 25 个百分点。打开重新打包后,结果通常比一开始更小。
怎么确认文件已经线性化?
在 Acrobat 里打开结果,查看文档属性:「快速 Web 查看」显示为「是」。在命令行下,qpdf --check 会报告文件已线性化。要试真正的效果,你还需要从支持 Range 请求的服务器上用 HTTP 提供这个文件。
文件会被上传到什么地方吗?
不会。qpdf 以 WebAssembly 的形式运行在你浏览器的 Web Worker 里,所以文档会一直留在你的设备上,直到你自己发布它。页面加载之后,即使没有网络也能用。

相关工具