Skip to main content

PDF Sentinel is a lightweight safety inspection library for PDF documents. It detects oversized, vector-heavy, or otherwise resource-intensive pages (like blueprints) that could slow down or crash OCR and pipelines.

Project description

PDF Sentinel

PDF Sentinel is a lightweight safety inspection library for PDF documents. It detects oversized, vector-heavy, or otherwise resource-intensive pages (like blueprints) that could slow down or crash OCR and pipelines.


Features

  • Detects dangerous or heavy PDF pages:

    • Large page dimensions (A0, engineering blueprints, etc.)
    • Massive embedded images
    • Vector-heavy drawings (architectural plans)
    • Pages that exceed safe rasterization thresholds
  • Returns simplified or detailed analysis for pages and files

  • Configurable limits (page size, pixel thresholds, etc.)

  • Optional JSON response for easy API integration


Installation

pip install PDFSentinel

This will install the library from PyPI and make it available to import in your project.


Usage

Simplified file safety check

from pdfsentinel import PDFSentinel

sentinel = PDFSentinel()
result = sentinel.is_file_safe("samples/test.pdf")
print(result)

Output (Python dict):

{
    "file_name": "test.pdf",
    "pages": 23,
    "is_file_safety": true,
    "unsafety_pages": []
}

You can also get JSON-formatted output directly:

print(sentinel.is_file_safe("samples/test.pdf", json_response=True))

Simplified page safety check

print(sentinel.is_page_safe("samples/test.pdf", 2, json_response=True))

Example output:

{
    "file_name": "test1.pdf",
    "page": 24,
    "is_page_safety": false,
    "errors": [
        "page_too_large:2592.0x1728.0",
        "too_many_vector_ops:33035",
        "raster_estimate_too_big:77760000"
    ]
}

Full file analysis

print(sentinel.file_analysis("samples/test.pdf", json_response=True))

Output:

{
    "file_name": "test1.pdf",
    "pages": 2,
    "is_file_safety": true,
    "results": [
        {
            "page": 1,
            "is_page_safety": true,
            "errors": [],
            "page_width": 612.0,
            "page_height": 792.0,
            "max_image_pixels": 0,
            "max_vectors_operations": 58,
            "max_raster_pixels": 8415000
        },
        {
            "page": 2,
            "is_page_safety": false,
            "errors": [
                "page_too_large:2592.0x1728.0",
                "too_many_vector_ops:33035",
                "raster_estimate_too_big:77760000"
            ],
            "page_width": 612.0,
            "page_height": 792.0,
            "max_image_pixels": 0,
            "max_vectors_operations": 58,
            "max_raster_pixels": 8415000
        }
    ]
}

Single page detailed analysis

print(sentinel.page_analysis("samples/test.pdf", 3, json_response=True))

Configuration

You can override safety thresholds per call:

sentinel.is_file_safe("samples/test.pdf", config={
    "max_page_size": 1800,
    "max_image_pixels": 10_000_000,
    "max_vectors_operations": 1000,
    "max_raster_pixels": 20_000_000
})
Parameter Default Description
max_page_size 2000 Max page dimension in points
max_image_pixels 20,000,000 Max embedded image size (w × h)
max_vectors_operations 1500 Max allowed vector drawing operations
max_raster_pixels 30,000,000 Estimated max rasterization size (at 300 dpi)

Testing Example

You can create a simple test_sentinel.py at the project root:

import PDFSentinel

sentinel = PDFSentinel()

result = sentinel.is_file_safe("samples/test.pdf", json_response=True)
print(result)

License

MIT License © 2025 — Not Empty Foundation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdfsentinel-1.0.0.tar.gz (4.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdfsentinel-1.0.0-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file pdfsentinel-1.0.0.tar.gz.

File metadata

  • Download URL: pdfsentinel-1.0.0.tar.gz
  • Upload date:
  • Size: 4.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pdfsentinel-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0b62d4eb3eae056a448ed57212a25bd97134b5c53275bfd110a1c2e2ed47f894
MD5 d09e218184cbee0b28da5b98ef6b54ae
BLAKE2b-256 cd9d3a31edb93ee31839dbb4fb9e25542f9b92f031060f09481d012f8fb57cd7

See more details on using hashes here.

File details

Details for the file pdfsentinel-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pdfsentinel-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pdfsentinel-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8a77af3c3e745a1c64a9f4f6c7dba229d9fdf92185bb60d95cffaf948d30f685
MD5 1599100438c6e711bf952a88dd6ac964
BLAKE2b-256 e1646f6cc46a5f615ed97f26d495ef9adfd0e3db60ecff3e404533d75e47cb73

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page