更改 pdf 的 CropBox 和文本颜色
我有一个 pdf 文件,在我的电子阅读器上几乎无法阅读。 页边距较大,导致文本较小。 文本颜色为浅灰色,在我的设备屏幕上呈现得非常微弱。
我想我可以通过更改以下方式使文件更清晰:
- CropBox 从
0 0 612 792
更改为60 70 525 725
- 文本颜色从
0.314 0.314 0.314 rg
> 到0 0 0 rg
我可以在 pdfbox 调试器应用程序中清楚地看到这些部分。不幸的是,它给了我一个只读视图。有没有办法加载 pdf 并将其所有部分复制到新的 pdf,同时仅更改 CropBox 和文本颜色?
% curl -O https://repo1.maven.org/maven2/org/apache/pdfbox/debugger-app/2.0.25/debugger-app-2.0.25.jar
% java -jar debugger-app-2.0.25.jar
I have a pdf that a nearly impossible to read on my ereader.
The margins are large which makes the text small.
The text color is light grey which is rendered very faintly on the screen of my device.
I think I can make the file more legible by changing:
- CropBox from
0 0 612 792
to60 70 525 725
- text color from
0.314 0.314 0.314 rg
to0 0 0 rg
I can clearly see these parts in the pdfbox debugger app. Unfortunately it gives me a read-only view. Is there a way to load the pdf and copy all of its parts to a new pdf while altering only the CropBox and text color?
% curl -O https://repo1.maven.org/maven2/org/apache/pdfbox/debugger-app/2.0.25/debugger-app-2.0.25.jar
% java -jar debugger-app-2.0.25.jar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个肮脏的黑客似乎有效,但我觉得必须有更好的方法。
解码 pdf
decoded.pdf
现在包含与原始 pdf 相同的内容,但不再应用 FlatDecode。这意味着内容是“清晰的”。使用hexfiend编辑decoded.pdf
替换:0.000 0.000 0.000 rg
替换:/CropBox [60 70 525 725.00000]
文件现在非常大...因此在预览中打开它并导出为 pdf。可悲的是,这种重新压缩的方式会丢弃目录。
我已经找到 krop,一个简单的Linux 下裁剪 PDF 文件页面的图形工具。这比在十六进制编辑器中编辑文件要容易得多。但不会改变文本颜色。
This dirty hack seems to work, but I feel like there has to be a better way.
Decode the pdf
decoded.pdf
now contains the same contents as the original pdf, but FlatDecode is no longer applied. This means the content is "legible".Edit decoded.pdf with hexfiend
Replace: 0.000 0.000 0.000 rg
Replace: /CropBox [60 70 525 725.00000]
The file is now very large ... so open it in preview end export to pdf. This way of re-compressing sadly throws away the table of contents.
I've since found krop, a simple graphical tool to crop the pages of PDF files for linux. It is much easier than editing the file in a hex editor. Doesn't change text color though.