我想做与OCR相反的事情,我不想将图像转换为文本,我想将PDF中的所有文本转换为图像,以便不能随意选择和复制它。
在Acrobat Pro中可以使用,但我真的很想在Linux命令行中使用某些功能,因为我要处理许多此类PDF,并且它们目前都在网站上。如果我可以在服务器上进行此更改,则可以节省我几个小时的下载,在Acrobat中处理,重新上传的工作,而这需要通过我的CMS界面进行,这非常慢。
因此,如果有一些PDF工具可以轻松做到这一点,那么我可以在终端上使用它,这真是太棒了。
我想您的目标是使从PDF中选择和复制文本变得更加困难。因为那是您可以提出的唯一可实现的目标。(如果有一种方法可以在屏幕上查看PDF页面,那么有一种方法可以某种方式访问文本或图像内容,尽管比仅粘贴'n'粘贴更为困难...我想你是意识到这一点。)
您有三种选择:
只要使用正确的工具,这3种方法中的每种方法都非常易于应用。:-)
对于每种方法,您都可以在命令行上使用“免费和开源软件”工具。(这些工具均可用于Linux,Mac OSX,Unix或Windows。)
请参见下面的每种方法的详细讨论。
convert
)您可以像这样简单地使用ImageMagick的convert
命令:
convert \
pdf-with-fonts.pdf \
pdf-with-images.pdf
ImageMagick只能直接使用光栅图像,而不能使用任何其他格式。由于它无法直接处理PDF,因此它将自动采用Ghostscript作为其委托。因此,也需要安装Ghostscript!Ghostscript将创建ImageMagick输入所需的光栅图像。
您可以通过-verbose
在命令行中添加switch来观察使用Ghostscript作为后台进程的ImageMagick进程。
默认情况下,convert
将使用72ppi的分辨率。这可能不足以很好地阅读(但通过将OCR软件应用于输出来规避“保护”会更加困难。)
上图显示了以600%缩放级别使用ImageMagick使用的默认分辨率(72 PPI)创建的像素化PDF页面的屏幕截图。如果需要更好的分辨率(例如200 PPI),请将-density 200
参数添加到命令行:
convert \
-density 200 \
pdf-with-fonts.pdf \
pdf-with-images.pdf
上图显示了ImageMagick创建的具有200 PPI更高分辨率的像素化PDF页面的照片(也在600%缩放级别)。
请注意,当我以默认分辨率72 PPI测试上述命令时,包含所有文本且大小为1 MB的219页PDF产生了23 MB的输出文件。在MacBook上生成大约需要2分钟。200ppi PDF产生了110 MB,耗时11分钟准备就绪...
如果分辨率足够好,很容易避免页面像素化:OCR会很好地工作。分辨率低,对于人类来说仍然可能是可读(可猜测)的,但是对于机器而言,很难获得良好的OCR结果。
您可以使用最新,最新,最出色的Ghostscript版本。那是v9.15版本。使用检查安装的版本gs -version
。
最新版本v9.15包含一个新的命令行参数--dNoOutputFonts
。此参数会将所有字形形状转换为轮廓,并删除所有嵌入的字体:
gs \
-o pdf-with-outlines.pdf \
-sDEVICE=pdfwrite \
pdf-with-fonts.pdf
在我的测试中,相同的219页PDF(大小为1 MB)转换为186 MB的输出文件,转换需要6分钟。
轮廓线的优点是页面的文本保持清晰,清晰和无像素,并且您可以在不降低清晰度的情况下以任意级别放大文本。您可以在下一个屏幕截图中看到:
缺点是文件的大小。(顺便说一句,我测试了相同的方法,使用Adobe Acrobat Pro XI将文本转换为轮廓,结果文件大小为61 MByte,需要15分钟的处理。)
绕开此措施很容易:OCR可以正常工作。
qpdf
)What is not so well known, is that you can 'protect' or ('encrypt') a PDF with empty passwords (the 'user' as well as the 'owner' passwords). This allows all PDF reader/viewer software to open the file without asking for a password, only popping up the password dialog when trying to copy text from a page or when trying to print the file.
QPDF has quite good support for this:
qpdf \
--encrypt "" "" 40 \
--print=n \
--modify=n \
--extract=n \
-- \
uncrypted.pdf \
crypted.pdf
What do all these command options mean?
--encrypt "" "" 40
:
This sets both passwords (user and owner) to the empty string and the key length to 40 bits.
--print=n
:
This disables printing of the PDF.
--modify=n
:
This disables modification of the PDF.
--extract=n
:
This disables text and image extraction of the PDF.
--
:
This is required to signal the end of encryption options.
There are more (and different) detailed options available with QPDF if you use a 128 or 256 bit keylength. Other available options include --modify=[annotate|form|assembly]
which would allow the filling of forms, adding of annotations or assembling the document with other PDFs (while at the same time still disallowing copy'n'paste or print).
This command
qpdf --show-encryption crypt.pdf
Will show the details about any file's 'encryption' settings. Example:
extract for accessibility: not allowed
extract for any purpose: not allowed
print low resolution: not allowed
print high resolution: not allowed
modify document assembly: not allowed
modify forms: allowed
modify annotations: allowed
modify other: not allowed
modify anything: not allowed
BTW: Leaving the password empty in the two dialogs shown above will not help with (most? or all? haven't tested...) PDF viewers. It still won't unlock to copy or print.
The advantage of this method lies in its fast execution and its almost identical file size.
Of course, it is just as easy to remove the 'encryption' again:
qpdf --decrypt crypted.pdf decrypted.pdf
For fast results, identical file sizes, and easy-to-remove protection against 'casual' selection and copying of text, use 'protection'/'encryption' with an empty password.
For slow results, and potentially huge file sizes (but not always good looking pages) and a bit more-work-to-remove-the-protection, use pixelization for all pages.
For even slower results (but always better looking pages) and also more-work-to-remove-the-protection, use the vector outlining method of all text.
请始终注意,所有这些方法均不能绝对保护PDF页面的内容。它们只会使提取更加不便。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句