我有 PDF 文件,我想在其中尽可能多地修剪所有空白区域。它必须自动检测并执行。
我使用 Foxit 阅读器,它可以选择在查看时自动裁剪页面。
但我正在寻找 Linux 中的命令行解决方案。
我尝试了PDFCrop,但它统一裁剪了所有页面。我希望它使用以下命令根据每个页面周围的空白进行裁剪:
pdfcrop input.pdf output.pdf
Run Code Online (Sandbox Code Playgroud)
但它只能部分工作,有些页面被裁剪,有些则没有。
去除边距的最佳方法是使用 pdfCropMargins https://pypi.org/project/pdfCropMargins/
安装:
pip install pdfCropMargins --upgrade
Run Code Online (Sandbox Code Playgroud)
现在我们可以使用该命令pdf-crop-margins以我们想要的方式裁剪 pdf
我想裁剪所有页面,然后在四周添加 6bp 边距。我可以这样做
pdf-crop-margins -v -p 0 -a -6 input.pdf
-v : Verbose
-p : how much percentage of margin to be retained. We want the bounding box triming all the white margins on all sides. So say 0%
-a : Note: first -p is applied to create a bounding box.
IN this option it applies further on the bounding box after -p is applied. we can remove or add margin. Negative means add margin to the bounding box. So it will add 10bp all around after cliping
Run Code Online (Sandbox Code Playgroud)
输出文件附有 _cropped
我还检查了裁剪后的文件,所有内容和链接都完好无损。