Package: pdf-toolbox
PDF TOOLBOXThis package is designed to be used as an extensible library.PDF TOOLBOX allows extracting, parsing, structuring and storing
text from PDFs.This package emerges as the solution to a challenge in which I
had to obtain and store clinical data but can be used for any other purpose.Package installationDownload and install this package.
To install this package you should run:python3setup.pyinstallExtracting PDF TextPDF TOOLBOX it is designed to read PDFs from multiple sources.Thepdf.readers.filereadermodule implements the reading of PDFs stored as files.
To read PDFs stored in memory, in a rabbitmq or in another data source,
it is necessary to create your own implementation that respects the
interface defined inpdf.domain.pdfreader.Example usageRetrieving text from a PDF file:frompdf_toolbox.pdf.readers.filereaderimportFilePDFReaderpdf_reader=FilePDFReader("inputs/report.pdf")pdf_text=pdf_reader.extract_text()Parsing PDF TextPDF text can have as parsers as PDF types are in the world.The provided parser parses the PDF text of the challenge.
The provided parser obtains the text of a specific clinical
PDF and returns its information structured in a dictionary.Example usage:frompdf_toolbox.text_extraction.report_parsers.challenge_parserimportChallengeParserchallenge_parser=ChallengeParser(pdf_text)pdf_data=challenge_parser.parse()You can define your own parser for other PDF types by implementing theReportParserinterface located intext_extraction.domain.report_parser.Storing PDF parsed dataCreating an identifier for the reportBefore saving the report data we should have defined an identifier for it. This package has a shortcut for it.The methodcreate_idreturns a new uuid version 4 identifier.Example usagefrompdf_toolbox.shared.utilsimportcreate_idreport_id=create_id()Saving report dataThe use of a JSON file as a storage backend is implemented in this package.Example usagefrompdf_toolbox.report_storage.storages.json_storageimportJSONStoragejson_storage=JSONStorage("demo.json")json_storage.save(pdf_data,report_id)Any type of backend can be implemented without losing compatibility with the rest of the code. Every storage backend must implement the interfacereport_storage.domain.storage.Storage.Running testsTo run the tests of this package you must install dev_requirements.txt and
run pytest inside pdf_toolbox folder.pipinstall-rdev_requirements.txtcdpdf_toolbox
pytestLICENSE MITCopyright 2022 Samuel López SauraPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.