更改 pdf 的 CropBox 和文本颜色

发布于 2025-01-15 08:25:57 字数 705 浏览 2 评论 0原文

我有一个 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

屏幕截图pdfbox 调试器应用程序,其中突出显示了 CropBox 和 rg

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 to 60 70 525 725
  • text color from 0.314 0.314 0.314 rg to 0 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

screenshot of pdfbox debugger-app with highlighted CropBox and rg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海夕 2025-01-22 08:25:57

这个肮脏的黑客似乎有效,但我觉得必须有更好的方法。

解码 pdf

% curl -O https://repo1.maven.org/maven2/org/apache/pdfbox/pdfbox-app/2.0.25/pdfbox-app-2.0.25.jar
% java -jar pdfbox-app-2.0.25.jar WriteDecodedDoc input.pdf decoded.pdf

decoded.pdf 现在包含与原始 pdf 相同的内容,但不再应用 FlatDecode。这意味着内容是“清晰的”。

使用hexfiend编辑decoded.pdf

  • 查找:0.314 0.314 0.314 rg
    替换:0.000 0.000 0.000 rg
  • 查找:/CropBox [0.0 0.0 612.0 792.0]
    替换:/CropBox [60 70 525 725.00000]

文件现在非常大...因此在预览中打开它并导出为 pdf。可悲的是,这种重新压缩的方式会丢弃目录。

屏幕截图查找并替换为 hexfiend

我已经找到 krop,一个简单的Linux 下裁剪 PDF 文件页面的图形工具。这比在十六进制编辑器中编辑文件要容易得多。但不会改变文本颜色。

This dirty hack seems to work, but I feel like there has to be a better way.

Decode the pdf

% curl -O https://repo1.maven.org/maven2/org/apache/pdfbox/pdfbox-app/2.0.25/pdfbox-app-2.0.25.jar
% java -jar pdfbox-app-2.0.25.jar WriteDecodedDoc input.pdf decoded.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

  • Find: 0.314 0.314 0.314 rg
    Replace: 0.000 0.000 0.000 rg
  • Find: /CropBox [0.0 0.0 612.0 792.0]
    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.

Screenshot of find and replace with hexfiend

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文