in reply to Adding xmp metadata using exiftool module

srikrishnan:

I'm sorry, but I'm unfamiliar with both Image::ExifTool and the internals of .pdf files. I'm writing just to offer a suggestion or two.

First, I notice that you restrict your variable names to 8 characters. While I'm a fan of shorter variable names, I'm surprised that you're wasting three of your characters by using a suffix of 'Val' on (nearly) all variables. I'd drop that habit like a hot rock. It's much more important to make your variable names clear than short.

For example, suppose you have a variable to represent a store owners Social Security Number. If you're a Java programmer, you might wind up with StoreOwnersSocialSecurityNumber or some such, which is much too long for my comfort. It looks like you might try to pack it down to $StOSSVal. I tend to use standardized abbreviations in my code to shorten variable names. In any industry, you'll have a particular set of frequently-used terms, and you should have (or create) a set of standard abbreviations for those terms. For example, a very common contraction of Social Security Number is SSN, so I'd use that throughout the application. So I'd shorten the variable to $StoreOwnerSSN, which is short and clear.

Secondly, it appears that the majority of those variables are used only once. Looking at how you're using them suggests the use of a hash, something like:

use strict; use warnings; use Image::ExifTool ':Public'; my @PDFAuthors = ( "Michael L. Oldham", "Dheeraj Khare", "Florante A. Quiocho", "Amy L. Davidson", "Jue Chen" ); my %StdPDFattrs = ( Description => "XXX 450, 515 (2007). doi:10.1038/XXX06264", Format => "application/pdf", Publisher => "XXX Publishing Group", Rights => " 2007 XXX Publishing Group", Charset => 'Latin', Title => "Crystal structure of a catalytic intermediate of the mal +tose transporter", Producer => "Acrobat Distiller 6.0.1 (Windows)", Cpyrt => " 2007 XXX Publishing Group", Identifier => "10.1038/XXX06264", EIssn => "1476-4687", EndingPage => "521", <<<SNIP>>> ); <<<SNIP>>> my $exifTool = new Image::ExifTool ':Public'; $exifTool->SetNewValue(); for my $Author (@PDFAuthors) { ($success, $errStr) = $exifTool->SetNewValue('Creator'=> $Author, +AddValue => 1); #print "Success: $success\n"; #print "Error $errStr\n"; } for my $Attribute (keys %StdPDFattrs) { $exifTool->SetNewValue( $Attribute, $StdPDFattrs{$Attribute} ); } <<<SNIP>>>

One last suggestion--Don't blindly double-space all your code. Whitespace has a single function: to make the program easy to read/understand. So use indentation and whitespace to make program structure clear.

Good luck with your problem!

...roboticus

P.S. As I was editing your code, I notice that you use 'XMP-RDF' in one place and 'XMP' elsewhere, perhaps your problem with XAP vs. XMP might be a consistency issue?

Update: Repaired CPAN link for module Image::ExifTool.

Update: Fixed %StdPDFattrs definition: I had square brackets instead of parenthesis. ++ to moritz for the catch!

Replies are listed 'Best First'.
Re^2: Adding xmp metadata using exiftool module
by srikrishnan (Beadle) on Dec 02, 2008 at 04:20 UTC
    Hi,

    Thanks for your suggestions. I will try to follow your valuable suggestions.

    Before that, just for your information.

    This is not an actual script. just I have try to make one sample for our customer. If we get approval from them, then we will write a script to extract all the datas from the source files. We are using a typesetting software called "3B2", which only supports scalar variables (not arrays and hashes)

    Anyway I hope your comments are very useful tips for us.

    Thanks,
    Srikrishnan