【问题标题】:Convert pdf to text using perl使用 perl 将 pdf 转换为文本
【发布时间】:2015-09-13 12:47:28
【问题描述】:

我有一个 pdf 文件,我想将其转换为文本文件。 我在 linux 命令行上尝试了 perl perl getpdftotext.exe fileName.pdf 但没有任何反应。 我试过CPAN CAM::PDF,但没有运气。

我在

处得到错误 Use of uninitialized value in string eq

C:/Strawberry/perl/site/lib/CAM/PDF.pm line 2362

输出文件为空。

我能够读取 pdf 文件中的页数。 my $num=$pdfone->numPages(); 返回正确的页数。 我使用的是 Adob​​e Reader X 版本 10.1.4。 我还尝试了一个渲染器,试图获得一页...第二个 sn-p 我也得到错误未初始化的值。我尝试过不同的pdf文件。 我正在使用草莓 perl。

enter code here

use CAM::PDF;
use CAM::PDF::PageText;
use PDF::API2;
    my $pdfone = CAM::PDF->new('WFServlet.pdf');
    my $outfile = "pdfWFServeltRESULT.txt"; 
    my @lines;
    open (OUTF, ">$outfile") || die "Can not open $outfile";

    for my $page (1 .. $pdfone->numPages()) {
       my $text = $pdfone->getPageText($page);
       @lines = split (/\n/, $text);
    }
    :
    : #snippet 2
 use CAM::PDF;
 use PDF::API2;
 use CAM::PDF::PageText;
 :
 my $pageone_tree = $pdfone->getPageContentTree(1);
 my $doc->getPageText(1);
 if (defined $doc) {
    print OUTF CAM::PDF::PageText->render($doc);
 }
 if (defined $pageone_tree) {
    print OUTF CAM::PDF::PageText->render($pageone_tree);
 }

【问题讨论】:

标签: perl pdf text


【解决方案1】:

我是 CAM::PDF 的作者,我衷心推荐使用不同的工具来完成这项任务。 :-) 我把文本提取写成一个有趣的实验,很快发现这是一个很难解决的问题。

【讨论】:

    【解决方案2】:

    Try Apache Tika. 我刚开始使用它为我正在开发的小型搜索引擎提取文本。到目前为止,它已经很不错了。

    perl 代码是这样的...

    my $text = `java -jar /some/path/tika-app-1.8.jar --text '/some/file'`
    

    【讨论】:

    • #!/bin/perl use strict;使用警告;使用 Cwd;我的 $tika = "C:/Apache_tiki"; chdir $tika;我的 $here = getcwd(); print "当前目录:$here\n";我的 $myfile="Example.pdf";我的 $text=java -jar tika-app-1.9.jar --text "$myfile";打印“文本:$text\n”;
    【解决方案3】:

    您为什么要使用 Perl?您可以使用许多其他 pdftotext 工具,它们可以更好地完成这项工作。试试 poppler-utils。最好的 pdf 转换工具之一。

    【讨论】:

    • CAM::PDF 是一项不错的工作。 Apache-tiki 工作正常。我喜欢它的地方在于它可以在 perl 脚本中调用。
    猜你喜欢
    • 2012-02-08
    • 1970-01-01
    • 1970-01-01
    • 2010-11-10
    • 1970-01-01
    • 1970-01-01
    • 2015-09-04
    • 1970-01-01
    相关资源
    最近更新 更多