自己找到了,方便大家,贴出来
#!/usr/bin/perl -w
use CAM::PDF;
use CAM::PDF::PageText;
$infile = $ARGV[0];
#print "the input PDF file is $infile\n";
$outfile = $ARGV[1];
#print "the output TXT file is $outfile\n";
open (OUTFILE, ">>$outfile") or die("cannot open file : $!");
$pdf = CAM::PDF->new($infile) || die "$CAM::PDF::errstr\n";
$num = $pdf->numPages();
foreach $p (1..$num)
{
#print "this is in page $p\n";
$str = $pdf->getPageText($p);
CAM::PDF->asciify(\$str);
print $str;
print OUTFILE "$str\n"; # write to file
}
close (OUTFILE);
perl-操作pdf
最新推荐文章于 2025-04-28 14:34:54 发布
本文分享了一个使用Perl语言编写的脚本,该脚本能从输入的PDF文件中提取所有页面的文字内容,并将这些文字保存到指定的TXT文件中。通过调用CAM::PDF模块,脚本实现了PDF文件的解析及文本提取功能。
3636

被折叠的 条评论
为什么被折叠?



