我有一个 pdf 文件,它使用 CAM::PDF 的 listimages.pl 什么都不返回,但使用 PDF::GetImages 将提取图像。使用以下代码,我可以找到图像对象,但我不知道如何将其提取到文件中。而且我无法弄清楚为什么命令行工具不起作用。
#!/usr/bin/perl -w
use strict;
use Cwd;
use File::Basename;
use Data::Dumper;
use CAM::PDF;
use CAM::PDF::PageText;
use CAM::PDF::Renderer::Images;
my $file = shift @ARGV || die "Usage: get-pdf-images /path/to/file.pdf \n";
my $pdf = CAM::PDF->new($file) || die "$CAM::PDF::errstr\n";
#print $pdf->toString();
foreach my $p ( 1 .. $pdf->numPages() ) {
my $page = $pdf->getPageContentTree($p);
my $str = $pdf->getPageText($p);
if (defined $str) {
# CAM::PDF->asciify(\$str);
print $str;
}
print "-------------------------------\n";
my $gs = $page->findImages();
my @imageNodes = @{$gs->{images}};
print "Found " . scalar @imageNodes . " images on page $p\n";
print Data::Dumper->Dump([\@imageNodes],['imageNodes']);
}
如果我运行 `pdfinfo.pl`,它会报告:
$ pdfinfo.pl test.pdf
File: test.pdf
File Size: 4599 bytes
Pages: 1
Author: þÿadmin01
CreationDate: Fri Jan 3 03:48:53 2014
Creator: þÿPDFCreator Version 1.7.2
Keywords:
ModDate: Fri Jan 3 03:48:53 2014
Producer: GPL Ghostscript 9.10
Subject:
Title: þÿVision6Card
Page Size: variable
Optimized: no
PDF version: 1.4
Security
Passwd: none
Print: yes
Modify: yes
Copy: yes
Add: yes
test.pdf 文件可以从这里下载:http ://imaptools.com:8080/dl/test.pdf