Automated PDF Document Processor in Python

Job ID: 39957793

Budget: €250 – €750 EUR

I need a Python-based system that can automatically process a single PDF file containing multiple mixed documents. The goal is to identify, classify, and split the PDF into separate files based on document type, and integrate the entire process into my n8n workflow.

The PDF files are generated by secretaries and contain various Belgian administrative documents such as pay slips, ID cards, property photos, energy reports (PEB), insurance simulations (ASRD), proof of personal funds, and more. The order of the pages is completely random and inconsistent from one file to another.

The script must analyze each page of the PDF individually and determine what type of document it belongs to. If the document spans multiple pages (e.g., one payslip across 3 pages), the script must correctly detect that and group them together. The system should then output individual PDFs for each detected document type.

To help you better understand the type of input, I have attached a sample PDF file as a reference. It contains a mix of documents like pay slips, ID card, property photos, and other common files we expect. You can use it to simulate the classification and splitting logic.

Key requirements:

Entire processing must be done in **Python**, not using any third-party black-box service.
The script must be **callable via webhook** inside my **n8n** automation system.
It should accept a PDF file as input, process it, then **return the separated PDFs** (grouped by document type) in a way compatible with n8n (e.g., as base64 data, file stream, or downloadable links).
The **full source code** must be delivered. We will host the script ourselves, so it must be clean, documented, and easy to run.
OCR will be used to analyze each page. If the OCR result contains **less than 50 characters**, the page will be treated as an **image**, and a separate prompt will be used to determine whether it is a photo of a real estate property. The response must follow a strict JSON format: {"isPropertyPhoto": true/false, "confidence": 0-100}.

Document classification:

The script must classify each page (or group of pages) according to a predefined list of over 50 document types (like FICHE_PAIE, COPIE_ID, RAPPORT_PEB, SIMULATION_ASRD, etc.).
For one specific case, FICHE_PAIE, the script must extract a date (the payroll period) and return a structured JSON format with the code, period (YYYY-MM), and text found.
All other types should return a simple JSON object like: {"code": "DOCUMENT_CODE"}.
If a page does not match any known type, return {"code": "INCONNU"}.
If a document could match multiple types, always choose the most specific and relevant one.

I will provide a detailed classification prompt that works very well for document-by-document analysis. Your task will be to adapt it to work on multi-document PDFs.

Example:
Input PDF contains: 3 payslips (each 3 pages), one ID card (front and back), property photos, a PEB report, and an ASRD simulation.
Output: 3 separate PDFs for payslips (named pay_slip_1.pdf, pay_slip_2.pdf, etc.), one PDF for the ID card (front + back combined), one PDF with property photos (if detected), and so on.

Deliverables:
Python script with full source code, using OCR and classification logic.
Integration guide or sample n8n node/webhook setup.
Flexible handling of unexpected page order, missing documents, and documents with variable lengths.
JSON response per page or per document with classification result.

The system must be reliable, accurate, and easily deployable on our own server. No external dependencies that lock us into a platform. Everything must be under our control.

Please apply only if you have strong experience with PDF processing, OCR, document classification (e.g., Hugging Face models like LayoutLM or Donut), and Python automation. Experience with n8n is a big plus.