How to read PDF document properties using Perl and CAM :: PDF?

I want to read some property of a PDF document using Perl. I already have CAM :: PDF installed on my system.

Is it possible to use this module to read the properties of a PDF document? If so, does someone give an example or refer to the appropriate routine that does this?

Or, should I use another module? If so, which module?

+4
source share
2 answers

I like the answer PDF :: API2 from Sinan Ünür. PDF :: API2 is awesome.

I am the author of CAM :: PDF. Sorry, I skipped this question before. CAM :: PDF comes with a cmdline tool for extracting such data (pdfinfo.pl).

My library does not officially support this, but it's easy to do if you don't mind hacking the insides.

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

I don't know much about CAM :: PDF . However, if you want to install PDF :: API2 , you can do:

 #!/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'
         }; 
+7
source

Source: https://habr.com/ru/post/1381756/


All Articles