importing pdfs from relative file locations
rhaynes74 opened this issue · comments
Hi folks, my .bib file has some 2500 papers. The pdfs exist for all but a dozen or so. The bibtex file has file= entries but the paths are relative paths, not absolute paths. Can I still import these in a way that I will be able to open them with bibmanager?
Best,
R Haynes
Hi,
The code should have no problems opening the PDFs once you link them to the entries. But note that when you link a PDF, the PDF file is moved form their current location to the bibmanager
home directory. Take a look at the docs for more details and examples:
https://bibmanager.readthedocs.io/en/latest/pdf.html#id1
Hi,
Ahhh, I think I understand now the original question. So, you have something like this for the entries, right? :
@article{bibtexkey,
author= ...,
...
file=/path/to/file.pdf,
...
}
No, the bibmanager code does not automatically recognize the file
key as the PDF from the entries. Users need to run one of the bibm pdf commands to link PDF files to the entries.
Since you have this format, you could link the PDFs to their BibTeX entries with a simple short script. I have a good idea of how to do this if you want. But keep in mind that then the files will be moved from their locations into the bibmanager home folder.
Hi, this Python3 script should do the trick.
import bibmanager.bib_manager as bm
import bibmanager.pdf_manager as pm
import bibmanager.utils as u
for bib in bm.load():
fields = u.get_fields(bib.content)
bibkey = next(fields)
for key, value, nested in fields:
if key == file:
try:
pm.set_pdf(bib.key, pdf=value, filename=None, replace=True)
except Exception as e:
print(str(e))