Branko
Branko

Reputation: 51

Read meta information from PDF using Perl module Image::ExifTool

I would like to read meta information from PDF using Perl module Image::ExifTool. I need to process PDFs using cross reference streams (as of PDF 1.5), and the other well established modules like PDF::API2 and CAM::PDF seem not to support them or have limited support.

Anyway, Image::ExifTool reads apparently a number of PDF tags, but if I run the following code:

use Image::ExifTool qw(:Public);
my $file = 'file.pdf';
my $exifTool = new Image::ExifTool;
$exifTool->ExtractInfo($file);
my @tagList = $exifTool->GetFoundTags('File');
for (@tagList){
    print "$_\n"
}

I do not seem to be able to get more then these tags:

ExifToolVersion
FileName
Directory
FileSize
FileModifyDate
FileAccessDate
FileCreateDate
FilePermissions
FileType
FileTypeExtension
MIMEType
PDFVersion
Linearized
Author
CreateDate
Creator (1)
ModifyDate
Producer (1)
Subject
Title (1)
XMPToolkit
CreateDate (1)
CreatorTool
ModifyDate (1)
MetadataDate
Producer
Format
Title
Description
Creator
DocumentID
InstanceID
PageLayout
PageMode
PageCount

In particular, I would like to get e.g. the PDF document catalog (Root tag). However running a code like this doesn't return any value:

my $tag = 'Root';
my $exifTool = new Image::ExifTool;
my $info = $exifTool->ImageInfo($file, $tag);
for (sort keys %$info) {
        print "$_ => $$info{$_}\n";
}

Help please :-)

Upvotes: 5

Views: 581

Answers (1)

bolav
bolav

Reputation: 6998

To see the parsing enable verbose mode: $exifTool->Options(Verbose => 1); It shows that the Root is indeed being parsed.

  7)  Root (SubDirectory) -->
  + [Root directory with 7 entries]
  | 0)  Metadata (SubDirectory) -->
  | + [Metadata directory with 3 entries]

I'm unsure what data you need from the root tag, but it's possible to get with the internal API: my $roottag = Image::ExifTool::GetTagTable('Image::ExifTool::PDF::Root');

From Image::ExifTool:

exports not part of the public API, but used by ExifTool modules:

Upvotes: 1

Related Questions