App-PDFLibrarian
view release on metacpan or search on metacpan
bin/pdf-lbr-edit-bib view on Meta::CPAN
# 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);
bin/pdf-lbr-import-pdf view on Meta::CPAN
exit 0;
}
}
# process IDs of PDF files opened in external viewer
my @pids;
# try to retrieve BibTeX records for all PDF files, and write BibTeX data 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)");
my $havebibstr = 0;
$npdffile = 0;
PDFFILE: foreach my $pdffile (@pdffiles) {
++$npdffile;
# open PDF file in external viewer
my $pid = run_async 'xdg-open', $pdffile;
# extract a DOI from PDF file, use for default query text
my @query_values = extract_query_values_from_pdf($pdffile);
bin/pdf-lbr-rebuild-links view on Meta::CPAN
# get list of PDF files in library
print STDERR "$Script: finding PDF files in library directory '$pdflibrarydir' ...\n";
my @pdffiles = find_pdf_files($pdflibrarydir);
# read BibTeX entries from PDF metadata
my @bibentries = read_bib_from_pdf(@pdffiles);
# 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);
exit 0 unless @bibentries > 0;
# find any PDF files without a BibTeX entry
my %bibentryfiles;
foreach my $bibentry (@bibentries) {
$bibentryfiles{$bibentry->get('file')} = 1;
lib/App/PDFLibrarian.pm view on Meta::CPAN
our %default_output_text_format;
our %query_databases;
our @EXPORT_OK = qw($cfgdir $pdflibrarydir $pref_query_database %bibtex_macros %default_filter %default_output_text_format %query_databases);
1;
INIT {
# allow printing of UTF-8 characters
binmode(STDOUT, "encoding(utf-8)");
# check for user home directory
croak "$Script: could not determine user home directory" unless defined($ENV{HOME}) && -d $ENV{HOME};
# create configuration directory
$cfgdir = File::BaseDir->config_home("pdflibrarian");
File::Path::make_path($cfgdir);
# read configuration file
my $cfgfile = File::Spec->catfile($cfgdir, "pdflibrarian.ini");
lib/App/PDFLibrarian/BibTeX.pm view on Meta::CPAN
}
# edit and re-read BibTeX entries, allowing for errors
my @errors;
while (1) {
while (1) {
# open new temporary file for editing BibTeX entries
my $fh = File::Temp->new(SUFFIX => '.bib', EXLOCK => 0) or croak "$Script: could not create temporary file";
binmode($fh, ":encoding(iso-8859-1)");
# write header message
if (@errors > 0) {
print $fh wrap("% ", "% ", <<"EOF");
PDFLibrarian has encountered several errors in parsing the following BibTeX records. These errors are indicated with comments next to the line where the errors occurred.
All errors MUST be corrected before the BibTeX records can be written back to the PDF file given by the 'file' field in each record.
To ABORT ANY CHANGES from being written, simply delete the relevant records, or the entire contents of this file.
EOF
lib/App/PDFLibrarian/BibTeX.pm view on Meta::CPAN
}
# BibTeX entries have been successfully read
last if @errors == 0;
}
{
# open new temporary file for editing BibTeX entries
my $fh = File::Temp->new(SUFFIX => '.bib', EXLOCK => 0) or croak "$Script: could not create temporary file";
binmode($fh, ":encoding(iso-8859-1)");
# format and print BibTeX entries
write_bib_to_fh({ fh => $fh }, format_bib({}, @bibentries));
$fh->flush();
# save handle to new temporary file; old temporary file is deleted
$oldfh = $fh;
# try to re-read BibTeX entries
read_bib_from_file(\@errors, \@bibentries, $fh->filename);
( run in 0.853 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )