我想用Perl阅读一些PDF文档属性.我已经在我的系统上安装了CAM :: PDF.
是否可以选择使用此模块来读取PDF文档的属性?如果是,有人可以举例或参考相关的子程序吗?
或者,我应该使用另一个模块吗?如果是哪个模块?
我对CAM :: PDF了解不多.但是,如果您愿意安装PDF :: API2,则可以执行以下操作:
#!/usr/bin/env perl
use strict; use warnings;
use Data::Dumper;
use PDF::API2;
my $pdf = PDF::API2->open('U3DElements.pdf');
print Dumper { $pdf->info };
Run Code Online (Sandbox Code Playgroud)
输出:
$VAR1 = {
'ModDate' => 'D:20090427131238-07\'00\'',
'Subject' => 'Adobe Acrobat 9.0 SDK',
'CreationDate' => 'D:20090427125930Z',
'Producer' => 'Acrobat Distiller 9.0.0 (Windows)',
'Creator' => 'FrameMaker 7.2',
'Author' => 'Adobe Developer Support',
'Title' => 'U3D Supported Elements'
};
我喜欢SinanÜnür的PDF :: API2答案.PDF :: API2非常棒.
我是CAM :: PDF的作者.对不起我之前错过了这个问题.CAM :: PDF附带了一个cmdline工具来提取这种数据(pdfinfo.pl).
我的图书馆不正式支持这个,但是如果你不介意入侵内部,那很容易做到.
#!perl -w
use strict;
use CAM::PDF;
my $infile = shift || die 'syntax...';
my $pdf = CAM::PDF->new($infile) || die;
my $info = $pdf->getValue($pdf->{trailer}->{Info});
if ($info) {
for my $key (sort keys %{$info}) {
my $value = $info->{$key};
if ($value->{type} eq 'string') {
print "$key: $value->{value}\n";
} else {
print "$key: <$value->{type}>\n";
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2654 次 |
| 最近记录: |