App-PDFLibrarian

 view release on metacpan or  search on metacpan

bin/pdf-lbr-edit-bib  view on Meta::CPAN

=head1 NAME

B<pdf-lbr-edit-bib> - Edit BibTeX bibliographic metadata in PDF files.

=head1 SYNOPSIS

B<pdf-lbr-edit-bib> B<--version>
B<pdf-lbr-edit-bib> B<--help>|B<-h>

B<pdf-lbr-edit-bib> I<links>|I<link-directories> ...

... I<links>|I<link-directories> ... B<|> B<pdf-lbr-edit-bib> ...

=head1 DESCRIPTION

B<pdf-lbr-edit-bib> reads BibTeX bibliographic metadata embedded in PDF files given by I<links> and/or within I<link-directories> in the PDF links directory. If I<links>|I<link-directories> are not given on the command line, they are read from standa...

The BibTeX metadata is written to a temporary file, which is then opened in an editing program, given either by the B<$VISUAL> or B<$EDITOR> environment variables, or else the program B<editor>. The B<macros> section of the configuration file is pars...

Any modifications are then written back to the PDF files given by the I<file> field in each BibTeX entry, and the PDF library links rebuilt as needed.

=head1 PART OF

App::PDFLibrarian

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2016--2026 Karl Wette. Licensed under the GNU General Public License, version 3 or later.

=cut

# handle help options
my ($version, $help);
GetOptions(
           "version" => \$version,
           "help|h" => \$help,
          ) or croak "$Script: could not parse options";
if ($version) { print "App::PDFLibrarian version $App::PDFLibrarian::VERSION\n"; exit 1; }
pod2usage(-verbose => 2, -exitval => 1) if ($help);

# get list of PDF files
my @pdffiles = find_pdf_files(get_file_list());
croak "$Script: no PDF files to edit" unless @pdffiles > 0;
foreach my $pdffile (@pdffiles) {
  croak "$Script: '$pdffile' is not in the PDF library" unless pdf_is_in_library($pdffile);
}

# read BibTeX entries from PDF metadata
my @bibentries = read_bib_from_pdf(@pdffiles);

# generate initial keys for BibTeX entries
generate_bib_keys(@bibentries);

# coerse entries into BibTeX database structure
foreach my $bibentry (@bibentries) {
  $bibentry->silently_coerce();
}

# write formatted BibTeX entries to a temporary file for editing
my $fh = File::Temp->new(SUFFIX => '.bib', EXLOCK => 0) or croak "$Script: could not create temporary file";
binmode($fh, ":encoding(iso-8859-1)");
write_bib_to_fh({ fh => $fh }, format_bib({}, @bibentries));

# edit BibTeX entries in PDF files
@bibentries = edit_bib_in_fh($fh, @bibentries);

# regenerate keys for modified BibTeX entries
generate_bib_keys(@bibentries);

# write BibTeX entries to PDF metadata; return modified BibTeX entries
@bibentries = write_bib_to_pdf(@bibentries);

# ensure all PDF files are part of library
update_pdf_lib(@bibentries);

# update links in PDF links directory to real PDF files
make_pdf_links(@bibentries);

# cleanup PDF links directory
cleanup_links();

exit 0;



( run in 1.178 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )