Skip to main content

Django Gotenberg

Project description

Djangotenberg

Djangotenberg is a library for connecting and using the Gotenberg PDF generator within your modern Django project. It allows you to convert HTML to PDF and manage PDF files easily.

Supported Tools

Currently, Djangotenberg supports the following Gotenberg tools:

  • Chromium: For converting HTML code to PDF files.
  • PDF Engines: For manipulating PDF files.
    • Merge PDFs: Combine multiple PDF files.
    • Read Metadata: Read metadata from PDF files.
    • Write Metadata: Edit or add metadata to PDF files.

Requirements

  • Python >= 3.9
  • Django >= 4.2
  • djangorestframework >= 3.16
  • requests >= 2.32
  • Gotenberg Server: A running Gotenberg server is required (running via Docker is recommended).

Installation

Install the library via pip: (Assuming the package is named djangotenberg)

pip install djangotenberg

Or install from Source code:

pip install .

Setup & Configuration

  1. Add djangotenberg to INSTALLED_APPS in your settings.py:

    # settings.py
    
    INSTALLED_APPS = [
        # ...
        'rest_framework',
        'djangotenberg',
        # ...
    ]
    
  2. Define GOTENBERG_CONFIG in settings.py to specify the Gotenberg server location:

    # settings.py
    
    GOTENBERG_CONFIG = {
        # Gotenberg server URL (Required)
        "GOTENBERG_URL": "http://localhost:3000",
        
        # API timeout in seconds (Optional, Default: 10)
        "GOTENBERG_API_TIMEOUT": 10,
    }
    

Usage

1. Using Client (Python Code)

You can use APIClient to send commands directly to Gotenberg.

from djangotenberg.client import APIClient

client = APIClient()

# Example: Convert HTML string to PDF
html_content = "<h1>Hello, Djangotenberg!</h1>"
response = client.html_to_pdf(html_content)

if response.ok:
    with open("output.pdf", "wb") as f:
        f.write(response.content)

2. Using Django Views (REST Framework)

Djangotenberg provides a pre-configured URL configuration that you can include directly in your project's urls.py.

Note: PDFView has permission_classes = [IsAuthenticated] set by default. Therefore, calling the API requires a Token or Login.

urls.py

from django.urls import path, include

urlpatterns = [
    # ...
    path('api/', include('djangotenberg.urls')),
    # ...
]

Available Endpoints:

Once installed and included (assuming mapped to /api/), you can access the API at the following endpoints:

  • POST /api/pdf-engine/html-to-pdf/: Convert HTML string to PDF
    • Body: { "html": "<h1>Content</h1>" }
  • POST /api/pdf-engine/merge/: Merge multiple PDF files
  • POST /api/pdf-engine/read-metadata/: Read PDF Metadata
  • POST /api/pdf-engine/write-metadata/: Write PDF Metadata

License

This project is licensed under the terms of the MIT lincense.

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

djangotenberg-0.1.1.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

djangotenberg-0.1.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file djangotenberg-0.1.1.tar.gz.

File metadata

  • Download URL: djangotenberg-0.1.1.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for djangotenberg-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dae4ca697c5b9b7d07cd112dd4d650d24d87ee475c60b81af14a0211b7f33087
MD5 8b4e3ae389039daf88ad392b2ab47615
BLAKE2b-256 c55ea7bcb69ca744b6cb26d1fafded6cdffce0cac5bbf87369720d27f79dcebc

See more details on using hashes here.

File details

Details for the file djangotenberg-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: djangotenberg-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for djangotenberg-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f69c64187ca5e47f5621f27cf720a5125cebe984964f5ea5c189a7526ab5b9c0
MD5 e6d17a98391894bbd33557e87a161050
BLAKE2b-256 cd9a3e8b0c3319ab90b0f6c79873f22462ecd51eeba255060c602f39ffaee8f6

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