Package: pdf2bib
pdf2bibpdf2bibis a Python library/command-line tool to extract bibliographic information from the .pdf file of a publication
(or from a folder containing several .pdf files), and automatically generate BibTeX entries. The pdf file can be either a paper published in a scientific journal (i.e. with
a DOI associated to it), or anarXivpreprint.pdf2bibcan be used either fromcommand line, or inside yourpython scriptor, only for Windows, directly from theright-click context menuof a pdf file or a folder.InstallationUse the package manager pip to install pdf2bib.pipinstallpdf2bibUnder Windows, it is also possible to addshortcuts to the right-click context menu.Table of ContentsInstallationDescriptionUsageCommand line usageCreating a bib file from a folderManually associate the correct identifier to a file from command lineUsage inside a python scriptManually associate the correct identifier to a fileInstalling the shortcuts in the right-click context menu of Windows-ContributingLicenseAcknowledgmentDonatingDescriptionpdf2bibrelies on the librarypdf2doi, which can automatically find a valid identifier of a scientific publication (i.e. either a DOI or an arxiv ID)
starting from a .pdf file. The identifier is also validated by querying public archives (e.g.,http://dx.doi.orgfor DOIs andhttp://export.arxiv.orgfor arxiv IDs).
The validation process returns raw BibTeX data (see alsohere), which is then used bypdf2bibto generate a valid BibTeX entry in the format@article{[LastNameFirstAuthor][PublicationYear][FirstWordTitle],
        title = ...,
        volume = ...,
        issue = ...,
        page = ...,
        publisher = ...,
        url = ...,
        doi = ...,
        journal = ...,
        year = ...,
        month = ...,
        author = ...
}In the current version the format of the BibTeX entry is not customizable by the user (unless you want to change the code - have fun :D),
but this functionality will be implemented in future realeses.Usagepdf2bibcan be used either as astand-alone applicationinvoked from the command line, or byimporting it in your python projector, only for Windows,
directly from theright-click context menuof a pdf file or a folder.Command line usagepdf2bibcan be invoked directly from the command line, without having to open a python console.
The simplest command-line invokation ispdf2bib'path/to/target'wheretargetis either a valid pdf file or a directory containing pdf files. Adding the optional command '-v' increases the output verbosity,
documenting all steps.
For example, when targeting the folderexampleswe get the following outputpdf2bibexamples-v[pdf2bib]:Lookingforpdffilesinthefolderexamples...[pdf2bib]:Found4pdffiles.[pdf2bib]:................[pdf2bib]:TryingtoextractdatatogeneratetheBibTeXentryforthefile:examples-s2.0-0021999186900938-main.pdf[pdf2bib]:Callingpdf2doi...[pdf2doi]:Method#1: Looking for a valid identifier in the document infos...[pdf2doi]:ValidatingthepossibleDOI10.1016/0021-9991(86)90093-8viaaquerytodx.doi.org...[pdf2doi]:TheDOI10.1016/0021-9991(86)90093-8isvalidatedbydx.doi.org.[pdf2doi]:AvalidDOIwasfoundinthedocumentinfolabelled'/identifier'.[pdf2bib]:pdf2doifoundavalididentifierforthispaper.Tryingtoparsethedataobtainedbypdf2doiintovalidBibTeXdata..[pdf2bib]:AvalidBibTeXentrywasgenerated.[pdf2bib]:................[pdf2bib]:TryingtoextractdatatogeneratetheBibTeXentryforthefile:examples\chaumet_JAP_07.pdf[pdf2bib]:Callingpdf2doi...[pdf2doi]:Method#1: Looking for a valid identifier in the document infos...[pdf2doi]:ValidatingthepossibleDOI10.1063/1.2409490viaaquerytodx.doi.org...[pdf2doi]:TheDOI10.1063/1.2409490isvalidatedbydx.doi.org.[pdf2doi]:AvalidDOIwasfoundinthedocumentinfolabelled'/identifier'.[pdf2bib]:pdf2doifoundavalididentifierforthispaper.Tryingtoparsethedataobtainedbypdf2doiintovalidBibTeXdata..[pdf2bib]:AvalidBibTeXentrywasgenerated.[pdf2bib]:................[pdf2bib]:TryingtoextractdatatogeneratetheBibTeXentryforthefile:examples\PhysRevLett.116.061102.pdf[pdf2bib]:Callingpdf2doi...[pdf2doi]:Method#1: Looking for a valid identifier in the document infos...[pdf2doi]:ValidatingthepossibleDOI10.1103/PhysRevLett.116.061102viaaquerytodx.doi.org...[pdf2doi]:TheDOI10.1103/PhysRevLett.116.061102isvalidatedbydx.doi.org.[pdf2doi]:AvalidDOIwasfoundinthedocumentinfolabelled'/identifier'.[pdf2bib]:pdf2doifoundavalididentifierforthispaper.Tryingtoparsethedataobtainedbypdf2doiintovalidBibTeXdata..[pdf2bib]:AvalidBibTeXentrywasgenerated.[pdf2bib]:................[pdf2bib]:TryingtoextractdatatogeneratetheBibTeXentryforthefile:examples\s41586-019-1666-5.pdf[pdf2bib]:Callingpdf2doi...[pdf2doi]:Method#1: Looking for a valid identifier in the document infos...[pdf2doi]:ValidatingthepossibleDOI10.1038/s41586-019-1666-5viaaquerytodx.doi.org...[pdf2doi]:TheDOI10.1038/s41586-019-1666-5isvalidatedbydx.doi.org.[pdf2doi]:AvalidDOIwasfoundinthedocumentinfolabelled'/doi'.[pdf2bib]:pdf2doifoundavalididentifierforthispaper.Tryingtoparsethedataobtainedbypdf2doiintovalidBibTeXdata..[pdf2bib]:AvalidBibTeXentrywasgenerated.[pdf2bib]:................
@article{jordan1986an,title={AnefficientnumericalevaluationoftheGreen'sfunctionfortheHelmholtzoperatoronperiodicstructures},volume={63},issue={1},page={222-235},publisher={ElsevierBV},url={http://dx.doi.org/10.1016/0021-9991(86)90093-8},doi={10.1016/0021-9991(86)90093-8},journal={JournalofComputationalPhysics},year={1986},month={3},author={KirkEJordanandGerardRRichterandPingSheng}}@article{chaumet2007coupled,title={Coupleddipolemethodtocomputeopticaltorque:Applicationtoamicropropeller},volume={101},issue={2},page={023106},publisher={AIPPublishing},url={http://dx.doi.org/10.1063/1.2409490},doi={10.1063/1.2409490},journal={JournalofAppliedPhysics},year={2007},month={1},author={PatrickC.ChaumetandC.Billaudeau}}@article{2016observation,title={ObservationofGravitationalWavesfromaBinaryBlackHoleMerger},volume={116},issue={6},publisher={AmericanPhysicalSociety(APS)},url={http://dx.doi.org/10.1103/PhysRevLett.116.061102},doi={10.1103/physrevlett.116.061102},journal={PhysicalReviewLetters},year={2016},month={2}}@article{arute2019quantum,title={Quantumsupremacyusingaprogrammablesuperconductingprocessor},volume={574},issue={7779},page={505-510},publisher={SpringerScienceandBusinessMediaLLC},url={http://dx.doi.org/10.1038/s41586-019-1666-5},doi={10.1038/s41586-019-1666-5},journal={Nature},year={2019},month={10},author={FrankAruteandKunalAryaandRyanBabbushandDaveBaconandJosephC.BardinandRamiBarendsandRupakBiswasandSergioBoixoandFernandoG.S.L.BrandaoandDavidA.BuellandBrianBurkettandYuChenandZijunChenandBenChiaroandRobertoCollinsandWilliamCourtneyandAndrewDunsworthandEdwardFarhiandBrooksFoxenandAustinFowlerandCraigGidneyandMarissaGiustinaandRobGraffandKeithGuerinandSteveHabeggerandMatthewP.HarriganandMichaelJ.HartmannandAlanHoandMarkusHoffmannandTrentHuangandTravisS.HumbleandSergeiV.IsakovandEvanJeffreyandZhangJiangandDvirKafriandKostyantynKechedzhiandJulianKellyandPaulV.KlimovandSergeyKnyshandAlexanderKorotkovandFedorKostritsaandDavidLandhuisandMikeLindmarkandErikLuceroandDmitryLyakhandSalvatoreMandrÃandJarrodR.McCleanandMatthewMcEwenandAnthonyMegrantandXiaoMiandKristelMichielsenandMasoudMohseniandJoshMutusandOferNaamanandMatthewNeeleyandCharlesNeillandMurphyYuezhenNiuandEricOstbyandAndrePetukhovandJohnC.PlattandChrisQuintanaandEleanorG.RieffelandPedramRoushanandNicholasC.RubinandDanielSankandKevinJ.SatzingerandVadimSmelyanskiyandKevinJ.SungandMatthewD.TrevithickandAmitVainsencherandBenjaminVillalongaandTheodoreWhiteandZ.JamieYaoandPingYehandAdamZalcmanandHartmutNevenandJohnM.Martinis}}Every line which begins with '[pdf2doi]' or '[pdf2bib]' is omitted when the optional command '-v' is absent. It is also possible to store all bibtex entries into
a text file, or into the system clipboard, by using the optional arguments-s FILENAME_BIBTEXand-clippdf2bibexamples-sbibtex.txt-clip
Allavailablebibtexentrieshavebeenstoredinthefilebibtex.txt
AllavailablebibtexentrieshavebeenstoredinthesystemclipboardA list of all optional arguments can be generated bypdf2bib --hpdf2bib--h
usage:pdf2bib[-h][-v][-sFILENAME_BIBTEX][-clip][-install--right--click][-uninstall--right--click][path[path...]]GenerateBibTeXentriesofscientificpublicationsstartingfromthepdffiles.Itrequiresaninternetconnection.

positionalarguments:pathRelativepathofthetargetpdffileorofthetargefolder.

optionalarguments:-h,--helpshowthishelpmessageandexit-v,--verboseIncreaseverbosity.Bydefault(i.e.whennotusing-v),onlythetextofthefoundbibtexentrieswillbeprintedasoutput.-sFILENAME_BIBTEX,--make_bibtex_fileFILENAME_BIBTEXCreateatextfileinsidethetargetdirectory,withnamegivenbyFILENAME_BIBTEX,containingthebibtexentryofeachpdffileinthetargetfolder(ifanyisfound).-clip,--save_bibtex_clipboardStoreallfoundbibtexentriesintotheclipboard.-install--right--clickAddashortcuttopdf2bibintheright-clickcontextmenuofWindows.Thisallowsyoutocopythebibtexentryofapdffile(orallpdffilesinafolder)intotheclipboardbyjustrightclickingonit!NOTE:thisfeatureisonlyavailableonWindows.-uninstall--right--clickUninstalltheright-clickcontextmenufunctionalities.NOTE:thisfeatureisonlyavailableonWindows.Creating a bib file from a folderpdf2bibcan be used to quickly generate a .bib file containining the BibTeX entries of all pdf files in a target folder, via the commandpdf2bib'path\to\target\folder'-sbibtex.bibThe generated .bib file can be imported into other software, such asZotero, to generate bibliograpies for, e.g. Microsoft Word.Manually associate the correct identifier to a file from command lineOccasionally, the BibTeX generation process will fail (or give wrong results) if the librarypdf2doi(whichpdf2bibrelies on to find a valid publication identifier)
fails to  retrieve a DOI/identifier (or maybe it retrives the uncorrect one). This problem can be fixed
by looking for the DOI/identifier manually and add it to the pdf metadata, by usingpdf2doias describedhere.
In this way, any future use ofpdf2bibon this file will always retrieve the correct BibTeX infos.Usage inside a python scriptpdf2bibcan also be used as a library within a python script. The functionpdf2bib.pdf2bibis the main point of entry.
The first input argument must be a valid path (either absolute or relative) to a pdf file or to a folder containing pdf files.
The same settings available in the command line operation (see above), are now available via the methodssetandgetof the objectpdf2bib.configFor example, we can scan the folderexampleswith reduced output verbosity,>>>importpdf2bib>>>pdf2bib.config.set('verbose',False)>>>path=r'.\examples'>>>result=pdf2bib.pdf2bib(path)>>>print(result[0]['metadata'])>>>print('')>>>print(result[0]['bibtex']){'title':"An efficient numerical evaluation of the Green's function for the Helmholtz operator on periodic structures",'volume':'63','issue':'1','page':'222-235','publisher':'Elsevier BV','url':'http://dx.doi.org/10.1016/0021-9991(86)90093-8','doi':'10.1016/0021-9991(86)90093-8','journal':'Journal of Computational Physics','year':1986,'month':3,'author':'Kirk E Jordan and Gerard R Richter and Ping Sheng','ENTRYTYPE':'article'}@article{jordan1986an,title={AnefficientnumericalevaluationoftheGreen's function for the Helmholtz operator on periodic structures},volume={63},issue={1},page={222-235},publisher={ElsevierBV},url={http://dx.doi.org/10.1016/0021-9991(86)90093-8},doi={10.1016/0021-9991(86)90093-8},journal={JournalofComputationalPhysics},year={1986},month={3},author={KirkEJordanandGerardRRichterandPingSheng}}The output of the functionpdf2bib.pdf2bibis a list of dictionaries (or just a single dictionary if a single file was targeted).
Each dictionary has the following keysresult['identifier']        = DOI or other identifier (or None if nothing is found)
result['identifier_type']   = string specifying the type of identifier (e.g. 'doi' or 'arxiv')
result['path']              = path of the pdf file
result['method']            = method used by pdf2doi to find the identifier
result['validation_info']   = Raw BibTeX data.
result['metadata']          = Dictionary containing bibtex info
result['bibtex']            = A string containing a valid bibtex entryThe elementresult['metadata']is a dictionary containing the most typical bibtex infos.
The specific keys contained in this dictionary, and their format, will depend on several factors, such as (1) if the paper was associated to a DOI or to an arxiv ID,
(2) which method was used bypdf2doito validate the paper identifier, and (3) which data is available for this paper in the relevant archive.
When the paper is associate to a DOI, theresult['metadata']dictionary will always contain at least the keys'title', 'author', 'journal', 'volume', 'issue', 'page', 'publisher', 'url', 'doi', 'year', 'month', althought some of them might be empty. When the paper is associated to an arxiv ID, theresult['metadata']dictionary will always contain the keys'title', 'author', 'ejournal', 'eprint', 'published', 'url', 'doi','arxiv_doi', 'year', 'month', 'day', 'ENTRYTYPE'Manually associate the correct identifier to a fileSimilarly to what describedabove, it is possible to associate a (manually found)
identifier to a pdf file also from within python, by using the functionpdf2doi.add_found_identifier_to_metadata:>>>importpdf2doi>>>pdf2doi.add_found_identifier_to_metadata(path_to_pdf_file,identifier)Installing the shortcuts in the right-click context menu of WindowsThis functionality is only available on Windows (and so far it has been tested only on Windows 10). It adds additional commands to the context menu of Windows
which appears when right-clicking on a pdf file or on a folder.The  menu commands allow to copy BibTeX entry of a pdf file (or all pdf files contained in a folder) into the system clipboard.To install this functionality, first installpdf2bibvia pip (as described above), then open a command promptwith administrator rightsand run$ pdf2bib  -install--right--clickTo remove it, simply run (again from a terminal with administrator rights)$ pdf2bib  -uninstall--right--clickIf it is not possible to run this command from a terminal with administrator rights, the batch filesherecan be alternatively used (see readme.MD file in the same folder for instructions), although it is still required to have
admnistrator rights.NOTE: when multiple pdf files are selected, and the right-click context menu commands are used,pdf2bibwill be called separately for each file, and thus
only the BibTeX entry of the last file will be stored in the clipboard. In order to copy the info of multiple files it is necessary to save them in a folder and right-click on the folder.ContributingPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.AcknowledgmentI am thankful to my friend and colleague Yarden Mazor for leading the beta-testing efforts for this project.DonatingIf you find this library useful (or amazing!), please consider making donations on my behalf to organizations that advocate for and promote free dissemination of science, such asarXivSci-HubWikipediaLicenseMIT