简体   繁体   English

如何使用Perl和CAM :: PDF阅读PDF文档属性?

[英]How can I read PDF document properties using Perl and CAM::PDF?

I want to read some PDF document property with Perl. 我想用Perl阅读一些PDF文档属性。 I already have CAM::PDF installed on my system. 我已经在我的系统上安装了CAM :: PDF

Is there an option to use this module to read the properties of a PDF document? 是否可以选择使用此模块来读取PDF文档的属性? If yes could someone give an example or refer to the relevant subroutine that does this? 如果是,有人可以举例或参考相关的子程序吗?

Or, should I use another module? 或者,我应该使用另一个模块吗? If yes which module? 如果是哪个模块?

I do not know much about CAM::PDF . 我对CAM :: PDF了解不多。 However, if you are willing to install PDF::API2 , you can do: 但是,如果您愿意安装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 };

Output: 输出:

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

I like the PDF::API2 answer from Sinan Ünür. 我喜欢SinanÜnür的PDF :: API2答案。 PDF::API2 is awesome. PDF :: API2非常棒。

I'm the author of CAM::PDF. 我是CAM :: PDF的作者。 Sorry I missed this question earlier. 对不起我之前错过了这个问题。 CAM::PDF comes with a cmdline tool to extract this sort of data (pdfinfo.pl). CAM :: PDF附带了一个cmdline工具来提取这种数据(pdfinfo.pl)。

My library does not support this officially, but it's easy to do if you don't mind hacking into internals. 我的图书馆不正式支持这个,但是如果你不介意入侵内部,那很容易做到。

#!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";
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM