pdf实际裁剪 [英] Pdf real cropping

查看:153
本文介绍了pdf实际裁剪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用linux shell裁剪pdf文档,然后提取该裁剪的pdf中的文本.

I need to crop a pdf document using the linux shell and then extract the text just in that cropped pdf.

我的想法是使用pdfcrop linux工具裁剪pdf,然后使用txt2pdf文本提取器工具提取裁剪区域中的文本,但是我意识到我正在考虑图像,并且当我尝试这样做的结果与对原始pdf而非未经裁剪的pdf的结果相同.

My idea was to crop a pdf using pdfcrop linux tool and then use a txt2pdf text extractor tool to extract the text just in the cropped area, but i've realized that i'm thinking on images, and when i try to do this the result is the same than doing it over the original, not cropped, pdf.

我想这是一个分层问题.由于pdf格式适用于图层,因此如果我不裁剪"所有图层,结果将包括我不想要的所有图层的所有信息.

I guess it's a layer problem. As the pdf format works with layers, if i don't "crop" all the layers, the result is gonna include all the information from all the layers, which i don't want.

如果有人对我如何在pdf中进行真正的所有图层裁剪"有所了解,我将非常感激.如果可能,或者我应该开始考虑其他解决方案.

I would appreciate so much if someone has any idea of how i could do a real "all layers cropping" in a pdf. If its possible or if i should start thinking on another solution.

TY

推荐答案

它不是分层的,它的事实是,裁剪PDF通常只需要简单地设置CropBox,而不会更改PDF的实际内容(除了CropBox).大多数文本提取代码将忽略CropBox并提取所有文本....

Its not layers, its the fact that cropping a PDF usually involves simply setting the CropBox, which doesn't alter the actual contents of the PDF (other than the CropBox) at all. Most text extraction code will ignore the CropBox and extract all the text....

您可以稍作努力,使用Ghostscript生成真正裁剪的PDF(尽管请注意,部分裁剪的字形仍将包括在内),然后从中提取文本.但这很丑.

You could, with some effort, use Ghostscript to produce a genuinely cropped PDF (though note that partially cropped glyphs will still be included) and then extract the text from that. But that's pretty ugly.

或者,Ghostscript和MuPDF都可以提取带有坐标信息的文本,这可能足以满足您的需求.

Alternatively Ghostscript and MuPDF can both extract text with co-ordinate information, which may be enough for your needs.

这篇关于pdf实际裁剪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆