2011-11-17 125 views
4

我想用Perl阅读一些PDF文档属性。我的系统上已安装CAM::PDF如何使用Perl和CAM :: PDF阅读PDF文档属性?

有没有使用此模块读取PDF文档属性的选项?如果是的话, 有人举例说明或参考相关的子程序这样做?

或者,我应该使用另一个模块?如果是的哪个模块?

回答

6

我喜欢从思南Ü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"; 
     } 
    } 
} 
7

我对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 }; 

输出:

$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' 
     };