如何从 Perl 中的 PDF 文件中提取文本? [英] How can I extract text from a PDF file in Perl?

查看:37
本文介绍了如何从 Perl 中的 PDF 文件中提取文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Perl 从 PDF 文件中提取文本.我一直在使用命令行中的 pdftotext.exe(即使用 Perl system 函数)从 PDF 文件中提取文本,这种方法工作正常.

I am trying to extract text from PDF files using Perl. I have been using pdftotext.exe from command line (i.e using Perl system function) for extracting text from PDF files, this method works fine.

问题是我们有像 α, β 这样的符号.以及生成的 txt 文件中未显示的 PDF 文件中的其他特殊字符.在文本中随机添加了一些额外的空格.

The problem is that we have symbols like α, β and other special characters in the PDF files which are not being displayed in the generated txt file. Also few extra spaces are being added randomly in the text.

是否有更好、更可靠的方法从 PDF 文件中提取文本,以便文本包含所有符号,如 α、β等等,文本将与 PDF 中的文本完全匹配(即没有多余的空格)?

Is there a better and more reliable way to extract text from PDF files such that the text will include all the symbols like α, β etc and the text will exactly match the text in the PDF (i.e without extra spaces)?

推荐答案

这些模块你可以实现从pdf中提取文本

These modules you can acheive the extract text from pdf

PDF::API2

CAM::PDF

CAM::PDF::PageText

来自 CPAN

   my $pdf = CAM::PDF->new($filename);
   my $pageone_tree = $pdf->getPageContentTree(1);
   print CAM::PDF::PageText->render($pageone_tree);

该模块尝试从 PDF 页面中提取顺序文本.这不是一个可靠的过程,因为 PDF 文本以任意顺序以图形方式排列.该模块使用了一些启发式方法来尝试猜测哪些文本紧挨着其他文本,但很容易被下标、非水平文本、字体更改、表单字段等所迷惑.

This module attempts to extract sequential text from a PDF page. This is not a robust process, as PDF text is graphically laid out in arbitrary order. This module uses a few heuristics to try to guess what text goes next to what other text, but may be fooled easily by, say, subscripts, non-horizontal text, changes in font, form fields etc.

抛开所有这些免责声明,它对于从简单的 PDF 文件中快速转储文本很有用.

All those disclaimers aside, it is useful for a quick dump of text from a simple PDF file.

这篇关于如何从 Perl 中的 PDF 文件中提取文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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