PDF Text Analyzer is a Python class that downloads a PDF from a URL, converts it to text, and performs text analysis. The analysis includes detecting the language of the text, removing stopwords, counting word frequencies, searching for specific phrases, and extracting metadata.
To use this class, you need Python 3.x and the following libraries:
requests
PyMuPDF
(fitz)nltk
langdetect
You can install the required libraries using the following command:
pip install requests PyMuPDF nltk langdetect
- Import the
PdfProcessor
class from the script. - Create an instance of
PdfProcessor
with a PDF URL. - Call the
main
method with an optional search phrase.
Example:
from pdf_processor import PdfProcessor
pdf_processor = PdfProcessor("https://example.com/document.pdf")
results = pdf_processor.main("example phrase")
print(results)
- PDF Download: Downloads PDFs with retry mechanism.
- Text Extraction: Extracts text using multiprocessing for efficiency.
- Language Detection: Detects the document language.
- Stop Words Removal: Removes stop words (with caching for optimization).
- Word Frequency Counting: Counts word frequencies.
- Phrase Search: Searches for specific phrases.
- Metadata Extraction: Extracts PDF metadata.
- Multilingual Support: Supports multiple languages (based on NLTK's stopwords corpus).
The script includes comprehensive error handling for:
- PDF download failures
- Text extraction issues
- Language detection problems
To install the PDF Text Analyzer, clone this repository and install the dependencies:
git clone https://github.com/cortega26/PDF-Text-Analizer.git
cd PDF-Text-Analyzer
pip install -r requirements.txt
If you want to contribute to this project, please follow these steps:
- Fork the repository.
- Create a new branch (git checkout -b feature/your-feature).
- Commit your changes (git commit -am 'Add new feature').
- Push to the branch (git push origin feature/your-feature).
- Submit a pull request.
For any bugs or feature requests, please open an issue.
This project is licensed under the MIT License. See the LICENSE file for details.