Skip to main content

A package for generating PDFs from structured data

Project description

📘 PDF Generator

PDF Generator is a Python package that converts structured list of dictionaries data into clean, styled PDF documents. It supports horizontal and vertical layouts, nested data structures, and extensive customization options.


🚀 Features

  • ✅ Convert dictionaries into formatted PDFs
  • 🧱 Support for horizontal and vertical layouts
  • 🎨 Customizable styles (titles, headers, cells)
  • 🪆 Handles complex nested structures
  • 📝 Word wrapping, text truncation, and alignment support
  • 🧩 Optional section titles using keys from your data

📦 Installation

pip install pdf-generator

📄 Basic Usage

from dict2pdf import PDFGenerator

data = [
    {
        "id": "P1001",
        "title": "Project Alpha",
        "status": "active",
        "lead_researcher": {
            "name": "Dr. Smith",
            "department": "Research"
        }
    }
]

PDFGenerator.generate_pdf_from_dict(
    data,
    output_file="output.pdf",
    title="Project Report"
)

🎨 Custom Styling

from dict2pdf import PDFGenerator

custom_styles = {
    'table_title': {
        'font_size': 24,
        'space_after': 30,
        'text_transform': 'uppercase'
    },
    'border_cell': {
        'border_width': 0.5,
        'border_color': colors.HexColor('#cccccc'),
    },
    'header_cell': {
        'back_color': '#f2f2f2',
        'font_size': 12,
        'font_name': 'Helvetica-Bold'
    },
    'horizontal_table_title': {
        'font_name': 'Helvetica-Bold',
        'font_size': 12,
        'text_color': colors.HexColor('#3498db'),
        'space_after': 12,
        'alignment': TA_LEFT,
        'text_transform': 'capitalize',
    },
}

PDFGenerator.generate_pdf_from_dict(
    data,
    output_file="styled_report.pdf",
    title="Styled Project Report",
    styles=custom_styles
)

📐 Layout Options

Horizontal Layout (default)

PDFGenerator.generate_pdf_from_dict(
    data,
    output_file="horizontal.pdf",
    title="Horizontal Layout",
    layout="horizontal"
)

Vertical Layout

PDFGenerator.generate_pdf_from_dict(
    data,
    output_file="vertical.pdf",
    title="Vertical Layout",
    layout="vertical"
)

📁 Custom Output Directory

PDFGenerator.generate_pdf_from_dict(
    data,
    output_file="report.pdf",
    title="Project Report",
    output_dir="output_pdfs"
)

🏷️ Use Title Key as Section Header

PDFGenerator.generate_pdf_from_dict(
    data,
    output_file="titled_report.pdf",
    title="Project Report",
    title_key="title"
)

🧩 Handling Complex Nested Data

complex_data = [
    {
        "course_details": {
            "code": "CS101",
            "name": "Intro to AI"
        },
        "instructors": {
            "main_instructor": "Prof. Alice",
            "assistants": ["Mark", "Linda", "Tom"]
        },
        "schedule": {
            "begin": "2025-09-01",
            "finish": "2026-06-30",
            "modules": [
                {"topic": "Foundations", "period": "2025-Q3"},
                {"topic": "Machine Learning", "period": "2025-Q4"},
                {"topic": "Final Project", "period": "2026-Q2"}
            ]
        }
    }
]

PDFGenerator.generate_pdf_from_dict(
    complex_data,
    output_file="complex_report.pdf",
    title="Detailed Project Report",
    nested_table=True
)

📚 License

This project is licensed under the MIT License.


🤝 Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

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

dict2pdf-1.0.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

dict2pdf-1.0.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dict2pdf-1.0.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for dict2pdf-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ffa3080c59ad2fe7d4ec7206a4c59f87ae114743f48aa84c574553a989a9217e
MD5 e1571baf4558fd31186e4991e559e736
BLAKE2b-256 5ee94ae8779b87248ad7d95de207bfd482531b82535782f5c28649f97d7ae403

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dict2pdf-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for dict2pdf-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8576d2d7f74c8791f775f806a713b941607df0d89689c51c99d6177c31647bb6
MD5 df0c9d8c17f1bf2115e74d9f77d232db
BLAKE2b-256 3e67603eef1204b9c8d15227bc85c5c677a39fd770cc173779374474f9a8c954

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