This FastAPI application provides an API for handling PDF files with three main functionalities:
- Merging multiple PDF files into one.
- Compressing a PDF file.
- Splitting a PDF file based on specified page ranges.
Note: For security reasons, the API currently uses ClamScan to scan for malware, which may result in longer processing times. Alternatively, you can use the VirusTotal API or its Python client. However, due to my commitment to open-source principles and privacy concerns, I have chosen not to use these alternatives.
This project also has a frontend application that you can use. Additionally, the web is hosted on a personal server. Please use it responsibly and adhere to security guidelines. Currently it is having some troubles with large pds
To use this API, ensure you have the following installed:
- Python 3.8+
- Ghostscript for PDF compression
- Clamscan for the malware analysis
- FastAPI for creating the API
- PyPDF2 for PDF manipulation
curlto make HTTP requests from the command line
- Clone the repository:
git clone https://github.com/Dax2405/PDFeditor-api.git
cd PDFeditor-api-
Create and activate a virtual environment:
python3 -m venv env source env/bin/activate # For Linux
-
Install the required Python packages:
pip install -r requirements.txt
-
Run the FastAPI application:
fastapi dev main.py
-
Install Ghostscript (if not already installed):
# On Debian/Ubuntu sudo apt install ghostscript # On Fedora sudo dnf install ghostscript # On Arch sudo pacman -S ghostscript
- Endpoint:
/unir_pdfs/ - Method:
POST - Description: Merges multiple PDF files into a single PDF.
- Parameters:
files: List of PDF files to be merged.
- Endpoint:
/comprimir_pdf/ - Method:
POST - Description: Compresses a single PDF file.
- Parameters:
file: PDF file to compress.
- Endpoint:
/dividir_pdf/ - Method:
POST - Description: Splits a PDF file within a specified page range.
- Parameters:
file: PDF file to split.start: Starting page number (1-indexed).end: Ending page number (1-indexed).
Below are curl commands for each endpoint. Replace localhost:8000 with the appropriate IP address or domain if the API is deployed.
To merge multiple PDF files:
curl -X POST "http://localhost:8000/unir_pdfs/" -F "files=@file1.pdf" -F "files=@file2.pdf" -o merged_output.pdfTo compress a single PDF file:
curl -X POST "http://localhost:8000/comprimir_pdf/" -F "file=@file_to_compress.pdf" -o compressed_output.pdfTo split a PDF from page start to end:
curl -X POST "http://localhost:8000/dividir_pdf/" -F "file=@file_to_split.pdf" -F "start=1" -F "end=3" -o split_output.pdfYou can also use the API on my personal hosting at https://pdf-api.dax-ec.ru/. Please note that it may take a longer time to process requests due to malware scanning. If you run the API locally, you can disable the malware scanner to speed up the process.
This project is licensed under the MIT License.