This Python project provides a simple yet powerful tool for analyzing PDF documents and counting the number of black and color pages. Whether you're working on document analysis, quality control, or just curious about the composition of your PDF files, this code helps you gain insights into the document's visual characteristics.
Key Features:
-
Easy Integration: With a few lines of code, you can integrate this functionality into your Python applications or workflows.
-
PDF Expertise: Utilizing the PyMuPDF (MuPDF) library, this project efficiently processes PDF files, making it suitable for a wide range of applications.
-
Color Page Detection: It accurately identifies color and black & white pages within the PDF document, providing valuable statistics.
-
Use Cases: This code can be employed in various scenarios, such as document archiving, printing optimization, or content analysis.
- Python: The primary programming language used for the project.
- FastAPI: A modern, fast (high-performance) web framework for building APIs with Python.
- PyMuPDF (MuPDF): A lightweight and efficient PDF processing library for Python.
- OpenCV: Used for image analysis and processing.
- Pillow (PIL): Python Imaging Library for working with images.
-
Run
pip install -r requirements.txt
to install all the requirements. -
- Run this command in your terminal
python -m venv myenv
. - Change your directory by
cd myenv/Scripts
if on windows. - Activate the virtual enviroment by running this command
source activate
. - Move out from virtual env to your Project Directory by
cd..
. - Install the packages if not present -
uvicorn
,fastapi
,fitz
,frontend
,tools
,opencv-python
,pillow
,python-multipart
,PyMuPDF
.
pip install uvicorn fastapi fitz frontend tools opencv-python pillow python-multipart PyMuPDF
- Run this command in your terminal
-
-Now Run the following command -
uvicorn main:app --reload
. -Open the localhost link on your browser and put/docs
at your endpoint to see the fastapi docs UI.-Now, Click on POST and then Try it out. -Click on Choose file to select a pdf, which you want to count the number of black and color pages. -Click on Execute.