- 论坛徽章:
- 0
|
本帖最后由 zhlong8 于 2011-07-20 23:10 编辑
想用手机看非pdf的文档有好办法了,使用perl模块CAM::PDF 把pdf文件转化为txt格式,O(∩_∩)O哈哈~,推荐,已使用过,请看如下代码:
#!/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] || 'test.txt;
#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); |
|