django-pdf-actions


Namedjango-pdf-actions JSON
Version 0.1.38 PyPI version JSON
download
home_pagehttps://github.com/ibrahimroshdy/django-pdf-actions
SummaryA Django app to export PDFs from admin actions
upload_time2025-02-12 17:48:57
maintainerNone
docs_urlNone
authorIbrahim Roshdy
requires_python>=3.8
licenseMIT
keywords django pdf admin export
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Django PDF Actions

<p align="center">
  <img src="docs/assets/logo.svg" alt="Django PDF Actions Logo" width="200" height="200">
</p>

[![PyPI version](https://img.shields.io/pypi/v/django-pdf-actions.svg?cache=no)](https://pypi.org/project/django-pdf-actions/)
[![Python Versions](https://img.shields.io/pypi/pyversions/django-pdf-actions.svg)](https://pypi.org/project/django-pdf-actions/)
[![Django Versions](https://img.shields.io/badge/django-3.2%20%7C%204.0%20%7C%204.1%20%7C%204.2-green.svg)](https://pypi.org/project/django-pdf-actions/)
[![Documentation](https://img.shields.io/badge/docs-github_pages-blue.svg)](https://ibrahimroshdy.github.io/django-pdf-actions/)
[![Documentation Status](https://readthedocs.org/projects/django-pdf-actions/badge/?version=latest)](https://django-pdf-actions.readthedocs.io/en/latest/?badge=latest)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Development Status](https://img.shields.io/badge/status-beta-yellow.svg)](https://pypi.org/project/django-pdf-actions/)
[![GitHub last commit](https://img.shields.io/github/last-commit/ibrahimroshdy/django-pdf-actions.svg)](https://github.com/ibrahimroshdy/django-pdf-actions/commits/main)
[![PyPI Downloads](https://img.shields.io/pypi/dm/django-pdf-actions.svg)](https://pypistats.org/packages/django-pdf-actions)
[![Total Downloads](https://static.pepy.tech/badge/django-pdf-actions)](https://pepy.tech/project/django-pdf-actions)
[![Published on Django Packages](https://img.shields.io/badge/Published%20on-Django%20Packages-0c3c26)](https://djangopackages.org/packages/p/django-pdf-actions/)

A Django application that adds PDF export capabilities to your Django admin interface. Export your model data to PDF documents with customizable layouts and styling.

## Prerequisites 

Before installing Django PDF Export, ensure you have:
- Python 3.8 or higher
- Django 3.2 or higher
- pip (Python package installer)

## Features

### 📊 Export Capabilities
- Export any Django model data to PDF directly from the admin interface
- Support for both portrait and landscape orientations
- Automatic pagination with configurable items per page
- Smart table layouts with automatic column width adjustment
- Support for Django model fields from list_display
- Batch export multiple records at once
- Professional table styling with grid lines and backgrounds

### 🎨 Design & Customization
Through the ExportPDFSettings model, you can configure:
- Page Layout:
  - Items per page (1-50)
  - Page margins (5-50mm)
  - Automatic column width calculation
  - Smart pagination handling
- Font Settings:
  - Custom font support (TTF files)
  - Configurable header and body font sizes
  - Default DejaVu Sans font included
- Visual Settings:
  - Company logo integration with flexible positioning
  - Header background color customization
  - Grid line color and width control
  - Professional table styling
- Display Options:
  - Toggle header visibility
  - Toggle logo visibility
  - Toggle export timestamp
  - Toggle page numbers
  - Customizable header and footer information
- Table Settings:
  - Cell spacing and padding control
  - Text wrapping with configurable character limits
  - Grid line customization
  - Header row styling

### 🌍 International Support
- Complete Unicode compatibility for all languages
- Arabic text support with automatic reshaping
- Bidirectional text handling
- Multi-language content support in the same document
- RTL (Right-to-Left) text support

## Quick Start

### 1. Installation

#### Using pip (Recommended)
```bash
pip install django-pdf-actions
```

#### From Source
If you want to install the latest development version:
```bash
git clone https://github.com/ibrahimroshdy/django-pdf-actions.git
cd django-pdf-actions
pip install -e .
```

### 2. Add to INSTALLED_APPS

Add 'django_pdf_actions' to your INSTALLED_APPS setting:

```python
INSTALLED_APPS = [
    ...
    'django_pdf_actions'
]
```

### 3. Run Migrations

```bash
python manage.py migrate
```

### 4. Set up Fonts

The package uses fonts from your project's `static/assets/fonts` directory. The default font is DejaVu Sans, which provides excellent Unicode support.

To use custom fonts:
1. Create the fonts directory if it doesn't exist:
   ```bash
   mkdir -p static/assets/fonts
   ```
2. Install the default font (DejaVu Sans):
```bash
python manage.py setup_fonts
```
3. Add custom fonts (optional):
   ```bash
   # Example: Installing Roboto font
   python manage.py setup_fonts --font-url "https://github.com/google/fonts/raw/main/apache/roboto/Roboto-Regular.ttf" --font-name "Roboto-Regular.ttf"

   # Example: Installing Cairo font for Arabic support
   python manage.py setup_fonts --font-url "https://github.com/google/fonts/raw/main/ofl/cairo/Cairo-Regular.ttf" --font-name "Cairo-Regular.ttf"
   ```

#### Font Directory Structure
After setup, your project should have this structure:
```
your_project/
├── static/
│   └── assets/
│       └── fonts/
│           ├── DejaVuSans.ttf
│           ├── Roboto-Regular.ttf (optional)
│           └── Cairo-Regular.ttf (optional)
```

### 5. Verify Installation

To verify the installation:
1. Start your Django development server
2. Navigate to the Django admin interface
3. Select any model with list view
4. You should see "Export to PDF (Portrait)" and "Export to PDF (Landscape)" in the actions dropdown

### 6. Add to Your Models

Import and use the PDF export actions in your admin.py:

```python
from django.contrib import admin
from django_pdf_actions.actions import export_to_pdf_landscape, export_to_pdf_portrait
from .models import YourModel

@admin.register(YourModel)
class YourModelAdmin(admin.ModelAdmin):
    list_display = ('field1', 'field2', ...)  # Your fields here
    actions = [export_to_pdf_landscape, export_to_pdf_portrait]
```

## Configuration

### PDF Export Settings

Access the Django admin interface to configure PDF export settings:

1. Go to Admin > Django PDF > Export PDF Settings
2. Create a new configuration with your desired settings
3. Mark it as active (only one configuration can be active at a time)

The active configuration will be used for all PDF exports across your admin interface.

### Available Settings

| Setting | Description | Default | Range |
|---------|-------------|---------|--------|
| Items Per Page | Rows per page | 10 | 1-50 |
| Page Margin | Page margins | 15mm | 5-50mm |
| Font Name | TTF font to use | DejaVuSans.ttf | Any installed TTF |
| Header Font Size | Header text size | 10 | 6-24 |
| Body Font Size | Content text size | 7 | 6-18 |
| Logo | Company logo | Optional | Image file |
| Header Background | Header color | #F0F0F0 | Hex color |
| Grid Line Color | Table lines color | #000000 | Hex color |
| Grid Line Width | Table line width | 0.25 | 0.1-2.0 |
| Table Spacing | Cell padding | 1.0mm | 0.5-5.0mm |
| Max Chars Per Line | Text wrapping | 45 | 20-100 |

### Technical Details

- **Python Compatibility**: Python 3.8 or higher
- **Django Compatibility**: Django 3.2, 4.0, 4.1, 4.2
- **Dependencies**: Automatically handled by pip
- **PDF Engine**: ReportLab
- **Character Encoding**: UTF-8
- **Paper Size**: A4 (default)

## Development

### Setting Up Development Environment

1. Clone the repository:
```bash
git clone https://github.com/ibrahimroshdy/django-pdf-actions.git
cd django-pdf-actions
```

2. Create a virtual environment:
```bash
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
```

3. Install development dependencies:
```bash
pip install -e ".[dev]"
```

4. Run tests:
```bash
pytest
```

## Documentation

For more detailed information, check out our documentation:
- [Installation Guide](https://ibrahimroshdy.github.io/django-pdf-actions/installation/)
- [Quick Start Guide](https://ibrahimroshdy.github.io/django-pdf-actions/quickstart/)
- [Configuration Guide](https://ibrahimroshdy.github.io/django-pdf-actions/settings/)

## License 

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Support

If you are having issues, please let us know by:
- Opening an issue in our [issue tracker](https://github.com/ibrahimroshdy/django-pdf-actions/issues)
- Checking our [documentation](https://ibrahimroshdy.github.io/django-pdf-actions/)

### Common Issues

1. Font Installation
   - Ensure your fonts directory exists at `static/assets/fonts/`
   - Verify font files are in TTF format
   - Check file permissions

2. PDF Generation
   - Ensure your model fields are properly defined in list_display
   - Check that an active PDF Export Settings configuration exists
   - Verify logo file paths if using custom logos


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ibrahimroshdy/django-pdf-actions",
    "name": "django-pdf-actions",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "django, pdf, admin, export",
    "author": "Ibrahim Roshdy",
    "author_email": "ibrahimrosh5@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/2a/0c/b92bd71fa12043a78fd8455bd0c958fb44ed8fad17421ecff77d42f1e387/django_pdf_actions-0.1.38.tar.gz",
    "platform": null,
    "description": "# Django PDF Actions\n\n<p align=\"center\">\n  <img src=\"docs/assets/logo.svg\" alt=\"Django PDF Actions Logo\" width=\"200\" height=\"200\">\n</p>\n\n[![PyPI version](https://img.shields.io/pypi/v/django-pdf-actions.svg?cache=no)](https://pypi.org/project/django-pdf-actions/)\n[![Python Versions](https://img.shields.io/pypi/pyversions/django-pdf-actions.svg)](https://pypi.org/project/django-pdf-actions/)\n[![Django Versions](https://img.shields.io/badge/django-3.2%20%7C%204.0%20%7C%204.1%20%7C%204.2-green.svg)](https://pypi.org/project/django-pdf-actions/)\n[![Documentation](https://img.shields.io/badge/docs-github_pages-blue.svg)](https://ibrahimroshdy.github.io/django-pdf-actions/)\n[![Documentation Status](https://readthedocs.org/projects/django-pdf-actions/badge/?version=latest)](https://django-pdf-actions.readthedocs.io/en/latest/?badge=latest)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Development Status](https://img.shields.io/badge/status-beta-yellow.svg)](https://pypi.org/project/django-pdf-actions/)\n[![GitHub last commit](https://img.shields.io/github/last-commit/ibrahimroshdy/django-pdf-actions.svg)](https://github.com/ibrahimroshdy/django-pdf-actions/commits/main)\n[![PyPI Downloads](https://img.shields.io/pypi/dm/django-pdf-actions.svg)](https://pypistats.org/packages/django-pdf-actions)\n[![Total Downloads](https://static.pepy.tech/badge/django-pdf-actions)](https://pepy.tech/project/django-pdf-actions)\n[![Published on Django Packages](https://img.shields.io/badge/Published%20on-Django%20Packages-0c3c26)](https://djangopackages.org/packages/p/django-pdf-actions/)\n\nA Django application that adds PDF export capabilities to your Django admin interface. Export your model data to PDF documents with customizable layouts and styling.\n\n## Prerequisites \n\nBefore installing Django PDF Export, ensure you have:\n- Python 3.8 or higher\n- Django 3.2 or higher\n- pip (Python package installer)\n\n## Features\n\n### \ud83d\udcca Export Capabilities\n- Export any Django model data to PDF directly from the admin interface\n- Support for both portrait and landscape orientations\n- Automatic pagination with configurable items per page\n- Smart table layouts with automatic column width adjustment\n- Support for Django model fields from list_display\n- Batch export multiple records at once\n- Professional table styling with grid lines and backgrounds\n\n### \ud83c\udfa8 Design & Customization\nThrough the ExportPDFSettings model, you can configure:\n- Page Layout:\n  - Items per page (1-50)\n  - Page margins (5-50mm)\n  - Automatic column width calculation\n  - Smart pagination handling\n- Font Settings:\n  - Custom font support (TTF files)\n  - Configurable header and body font sizes\n  - Default DejaVu Sans font included\n- Visual Settings:\n  - Company logo integration with flexible positioning\n  - Header background color customization\n  - Grid line color and width control\n  - Professional table styling\n- Display Options:\n  - Toggle header visibility\n  - Toggle logo visibility\n  - Toggle export timestamp\n  - Toggle page numbers\n  - Customizable header and footer information\n- Table Settings:\n  - Cell spacing and padding control\n  - Text wrapping with configurable character limits\n  - Grid line customization\n  - Header row styling\n\n### \ud83c\udf0d International Support\n- Complete Unicode compatibility for all languages\n- Arabic text support with automatic reshaping\n- Bidirectional text handling\n- Multi-language content support in the same document\n- RTL (Right-to-Left) text support\n\n## Quick Start\n\n### 1. Installation\n\n#### Using pip (Recommended)\n```bash\npip install django-pdf-actions\n```\n\n#### From Source\nIf you want to install the latest development version:\n```bash\ngit clone https://github.com/ibrahimroshdy/django-pdf-actions.git\ncd django-pdf-actions\npip install -e .\n```\n\n### 2. Add to INSTALLED_APPS\n\nAdd 'django_pdf_actions' to your INSTALLED_APPS setting:\n\n```python\nINSTALLED_APPS = [\n    ...\n    'django_pdf_actions'\n]\n```\n\n### 3. Run Migrations\n\n```bash\npython manage.py migrate\n```\n\n### 4. Set up Fonts\n\nThe package uses fonts from your project's `static/assets/fonts` directory. The default font is DejaVu Sans, which provides excellent Unicode support.\n\nTo use custom fonts:\n1. Create the fonts directory if it doesn't exist:\n   ```bash\n   mkdir -p static/assets/fonts\n   ```\n2. Install the default font (DejaVu Sans):\n```bash\npython manage.py setup_fonts\n```\n3. Add custom fonts (optional):\n   ```bash\n   # Example: Installing Roboto font\n   python manage.py setup_fonts --font-url \"https://github.com/google/fonts/raw/main/apache/roboto/Roboto-Regular.ttf\" --font-name \"Roboto-Regular.ttf\"\n\n   # Example: Installing Cairo font for Arabic support\n   python manage.py setup_fonts --font-url \"https://github.com/google/fonts/raw/main/ofl/cairo/Cairo-Regular.ttf\" --font-name \"Cairo-Regular.ttf\"\n   ```\n\n#### Font Directory Structure\nAfter setup, your project should have this structure:\n```\nyour_project/\n\u251c\u2500\u2500 static/\n\u2502   \u2514\u2500\u2500 assets/\n\u2502       \u2514\u2500\u2500 fonts/\n\u2502           \u251c\u2500\u2500 DejaVuSans.ttf\n\u2502           \u251c\u2500\u2500 Roboto-Regular.ttf (optional)\n\u2502           \u2514\u2500\u2500 Cairo-Regular.ttf (optional)\n```\n\n### 5. Verify Installation\n\nTo verify the installation:\n1. Start your Django development server\n2. Navigate to the Django admin interface\n3. Select any model with list view\n4. You should see \"Export to PDF (Portrait)\" and \"Export to PDF (Landscape)\" in the actions dropdown\n\n### 6. Add to Your Models\n\nImport and use the PDF export actions in your admin.py:\n\n```python\nfrom django.contrib import admin\nfrom django_pdf_actions.actions import export_to_pdf_landscape, export_to_pdf_portrait\nfrom .models import YourModel\n\n@admin.register(YourModel)\nclass YourModelAdmin(admin.ModelAdmin):\n    list_display = ('field1', 'field2', ...)  # Your fields here\n    actions = [export_to_pdf_landscape, export_to_pdf_portrait]\n```\n\n## Configuration\n\n### PDF Export Settings\n\nAccess the Django admin interface to configure PDF export settings:\n\n1. Go to Admin > Django PDF > Export PDF Settings\n2. Create a new configuration with your desired settings\n3. Mark it as active (only one configuration can be active at a time)\n\nThe active configuration will be used for all PDF exports across your admin interface.\n\n### Available Settings\n\n| Setting | Description | Default | Range |\n|---------|-------------|---------|--------|\n| Items Per Page | Rows per page | 10 | 1-50 |\n| Page Margin | Page margins | 15mm | 5-50mm |\n| Font Name | TTF font to use | DejaVuSans.ttf | Any installed TTF |\n| Header Font Size | Header text size | 10 | 6-24 |\n| Body Font Size | Content text size | 7 | 6-18 |\n| Logo | Company logo | Optional | Image file |\n| Header Background | Header color | #F0F0F0 | Hex color |\n| Grid Line Color | Table lines color | #000000 | Hex color |\n| Grid Line Width | Table line width | 0.25 | 0.1-2.0 |\n| Table Spacing | Cell padding | 1.0mm | 0.5-5.0mm |\n| Max Chars Per Line | Text wrapping | 45 | 20-100 |\n\n### Technical Details\n\n- **Python Compatibility**: Python 3.8 or higher\n- **Django Compatibility**: Django 3.2, 4.0, 4.1, 4.2\n- **Dependencies**: Automatically handled by pip\n- **PDF Engine**: ReportLab\n- **Character Encoding**: UTF-8\n- **Paper Size**: A4 (default)\n\n## Development\n\n### Setting Up Development Environment\n\n1. Clone the repository:\n```bash\ngit clone https://github.com/ibrahimroshdy/django-pdf-actions.git\ncd django-pdf-actions\n```\n\n2. Create a virtual environment:\n```bash\npython -m venv venv\nsource venv/bin/activate  # On Windows: venv\\Scripts\\activate\n```\n\n3. Install development dependencies:\n```bash\npip install -e \".[dev]\"\n```\n\n4. Run tests:\n```bash\npytest\n```\n\n## Documentation\n\nFor more detailed information, check out our documentation:\n- [Installation Guide](https://ibrahimroshdy.github.io/django-pdf-actions/installation/)\n- [Quick Start Guide](https://ibrahimroshdy.github.io/django-pdf-actions/quickstart/)\n- [Configuration Guide](https://ibrahimroshdy.github.io/django-pdf-actions/settings/)\n\n## License \n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Support\n\nIf you are having issues, please let us know by:\n- Opening an issue in our [issue tracker](https://github.com/ibrahimroshdy/django-pdf-actions/issues)\n- Checking our [documentation](https://ibrahimroshdy.github.io/django-pdf-actions/)\n\n### Common Issues\n\n1. Font Installation\n   - Ensure your fonts directory exists at `static/assets/fonts/`\n   - Verify font files are in TTF format\n   - Check file permissions\n\n2. PDF Generation\n   - Ensure your model fields are properly defined in list_display\n   - Check that an active PDF Export Settings configuration exists\n   - Verify logo file paths if using custom logos\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Django app to export PDFs from admin actions",
    "version": "0.1.38",
    "project_urls": {
        "Documentation": "https://ibrahimroshdy.github.io/django-pdf-actions",
        "Homepage": "https://github.com/ibrahimroshdy/django-pdf-actions",
        "Repository": "https://github.com/ibrahimroshdy/django-pdf-actions"
    },
    "split_keywords": [
        "django",
        " pdf",
        " admin",
        " export"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "08bb4f2e7054a75f0f748c182761c1d41e3affef37688ab5ed6abbae694fc95b",
                "md5": "05f6f7f310ebc64900c61394656facfa",
                "sha256": "d357ade177edc31fea7642992dc8cf02d2554ef10e6afbace53fdae788be50bd"
            },
            "downloads": -1,
            "filename": "django_pdf_actions-0.1.38-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "05f6f7f310ebc64900c61394656facfa",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 20779,
            "upload_time": "2025-02-12T17:48:55",
            "upload_time_iso_8601": "2025-02-12T17:48:55.534298Z",
            "url": "https://files.pythonhosted.org/packages/08/bb/4f2e7054a75f0f748c182761c1d41e3affef37688ab5ed6abbae694fc95b/django_pdf_actions-0.1.38-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2a0cb92bd71fa12043a78fd8455bd0c958fb44ed8fad17421ecff77d42f1e387",
                "md5": "6476d97a916e471c47febae60f98cfa5",
                "sha256": "b6342e31f12ddc5f54eeca5a28c304a824f4f1aaa7b1252ce58747e8ccc425bd"
            },
            "downloads": -1,
            "filename": "django_pdf_actions-0.1.38.tar.gz",
            "has_sig": false,
            "md5_digest": "6476d97a916e471c47febae60f98cfa5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 16995,
            "upload_time": "2025-02-12T17:48:57",
            "upload_time_iso_8601": "2025-02-12T17:48:57.323453Z",
            "url": "https://files.pythonhosted.org/packages/2a/0c/b92bd71fa12043a78fd8455bd0c958fb44ed8fad17421ecff77d42f1e387/django_pdf_actions-0.1.38.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-12 17:48:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ibrahimroshdy",
    "github_project": "django-pdf-actions",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "django-pdf-actions"
}
        
Elapsed time: 1.56237s