/ Published in: Perl
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/env perl # updatepdf.pl # parses a bibtex file and updates linked pdf file's metadata with bibtex data use strict; use warnings; use Getopt::Std; use Text::BibTeX; use PDF::API2; # option -x forces overwriting existing metadata # option -f provides the field name which contains the linked PDF file's path # default PDF file field name to "local-url" my %options; getopts('xf:', \%options); my $field = $options{'f'} || 'local-url'; # get input bibtex file's name from cl argument or read stdin my $bib = Text::BibTeX::File->new($in_file); # loops thorugh bibtex entries while (my $entry = new Text::BibTeX::Entry $bib) { # skip non-regular entries next unless $entry->parse_ok && $entry->metatype == BTE_REGULAR; # read local file field from the bibtex entry my $pdf_file = $entry->get($field); # skip file if doesn't exist or not a .pdf next; } # get PDF's info my %info = $pdf->info(); # set authour and title fields $info{'Author'} = $entry->get('author') $info{'Title'} = $entry->get('title') # write $pdf->info(%info); $pdf->update(); } }