# Django PDF View
[![Build Status](https://github.com/roknicmilos/django-pdf-view/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/roknicmilos/django-pdf-view/actions/workflows/ci.yml/?query=branch:main)
[![PyPI version](https://img.shields.io/pypi/v/django-pdf-view.svg)](https://pypi.org/project/django-pdf-view/)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![GitHub stars](https://img.shields.io/github/stars/roknicmilos/django-pdf-view.svg)](https://github.com/roknicmilos/django-pdf-view/stargazers)
[![GitHub issues](https://img.shields.io/github/issues/roknicmilos/django-pdf-view.svg)](https://github.com/roknicmilos/django-pdf-view/issues)
[![codecov](https://codecov.io/github/roknicmilos/django-pdf-view/graph/badge.svg?token=VF1XVECK7P)](https://codecov.io/github/roknicmilos/django-pdf-view)
## Purpose
The primary purpose of this Django package is to streamline the creation of PDF
documents and allow for easy viewing or downloading in the browser. The package
provides a **solid foundation of HTML and CSS for PDF file layout**. To use it,
simply create an HTML template for your PDF document, then create a view that
inherits from `PDFView` and define the necessary class attributes to generate
the PDF.
This approach enables developers to focus on crafting the content and styles of
their PDF pages without having to deal with complex layout issues.
### Key Features
- **Predefined Page Layout**: Includes built-in base HTML and CSS to help
structure your PDF pages efficiently.
- **Flexible PDF Content and Styling**: Easily create your own HTML template for
the PDF document and customize the appearance by applying your own CSS.
- **PDF View Response Options**: Seamlessly switch between viewing the PDF,
displaying the HTML content, and downloading the PDF file.
## Prerequisites
- [wkhtmltopdf](https://wkhtmltopdf.org/)
## Installation
```bash
pip install django-pdf-view
```
or
```bash
poetry add django-pdf-view
```
## Configuration
Add `django-pdf-view` to your `INSTALLED_APPS` in `settings.py`:
```python
INSTALLED_APPS = [
...
'django_pdf_view',
...
]
```
## Usage
In order to create your own PDF, you need to implement your own view and
template.
1. Create a new view to render the PDF:
```python
# my_app/views.py
from django_pdf_view.views.pdf_view import PDFView
class MyPDFView(PDFView):
template_name = 'my_app/my_pdf.html'
title = 'My PDF Document' # optional
filename = 'My PDF.pdf' # optional
css_paths = [ # optional
'my_pdf/css/my_pdf.css',
]
```
2. Create a new template to define the content of your PDF page:
```html
<!-- my_app/templates/my_app/pdf_page.html -->
<div class="page">
<h1 class="my-title">{{ title }}</h1>
<p class="my-text">{{ text }}</p>
<p class="my-text">Additional PDF page text.</p>
</div>
<!-- Define more <div class="page"> elements for additional pages -->
```
3. Add the new URL patterns to your project's `urls.py`:
```python
# my_app/urls.py
from django.urls import path
from my_app.views import MyPDFView
urlpatterns = [
path('pdf-file/', MyPDFView.as_view(response_type='pdf'), name='pdf-file'),
path('pdf-html/', MyPDFView.as_view(response_type='html'), name='pdf-html'),
path('pdf-download/', MyPDFView.as_view(response_type='download'), name='pdf-download'),
]
```
<br/>
4. Visit the belows listed URLs:
- To view the PDF
file: [http://localhost:8000/pdf-file/](http://localhost:8000/pdf-file/)
- To view the
HTML: [http://localhost:8000/pdf-html/](http://localhost:8000/pdf-html/)
- To download the PDF
file: [http://localhost:8000/pdf-download/](http://localhost:8000/pdf-download/)
### Default template context
- PDF document:
- `title`: Title of the PDF document (used in `<title>` tag).
- `css`: Content of the CSS files specified in the `css_paths` attribute.
- `content`: Content of the HTML template.
- `response_type`: Type of the response (`pdf`, `html` or `download`).
### `svg` template tag
`svg` template tag is provided by the `django-pdf-view` package. This template
tag can be used to include SVG images in the PDF document.
**Usage example**:
```html
{% load svg %}
<!-- Some HTML content -->
{% svg 'path/to/image.svg' %}
<!-- Some more HTML content -->
```
## Bugs/Requests
If you encounter any bugs or have any requests, please use
[GitHub issue tracker](https://github.com/roknicmilos/django-pdf-view/issues)
to report them.
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Raw data
{
"_id": null,
"home_page": null,
"name": "django-pdf-view",
"maintainer": "Milo\u0161 Rokni\u0107",
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": "roknic.milos.994@gmail.com",
"keywords": "pdf, pdf view, django pdf, django pdf view, generate pdf, django generate pdf",
"author": "Milo\u0161 Rokni\u0107",
"author_email": "roknic.milos.994@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/62/91/2a1c7b9a63a836fdeff919b86e834c86af68ed6126af84ba7fd8df7f2868/django_pdf_view-2.2.0.tar.gz",
"platform": null,
"description": "# Django PDF View\n\n[![Build Status](https://github.com/roknicmilos/django-pdf-view/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/roknicmilos/django-pdf-view/actions/workflows/ci.yml/?query=branch:main)\n[![PyPI version](https://img.shields.io/pypi/v/django-pdf-view.svg)](https://pypi.org/project/django-pdf-view/)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![GitHub stars](https://img.shields.io/github/stars/roknicmilos/django-pdf-view.svg)](https://github.com/roknicmilos/django-pdf-view/stargazers)\n[![GitHub issues](https://img.shields.io/github/issues/roknicmilos/django-pdf-view.svg)](https://github.com/roknicmilos/django-pdf-view/issues)\n[![codecov](https://codecov.io/github/roknicmilos/django-pdf-view/graph/badge.svg?token=VF1XVECK7P)](https://codecov.io/github/roknicmilos/django-pdf-view)\n\n## Purpose\n\nThe primary purpose of this Django package is to streamline the creation of PDF\ndocuments and allow for easy viewing or downloading in the browser. The package\nprovides a **solid foundation of HTML and CSS for PDF file layout**. To use it,\nsimply create an HTML template for your PDF document, then create a view that\ninherits from `PDFView` and define the necessary class attributes to generate\nthe PDF.\n\nThis approach enables developers to focus on crafting the content and styles of\ntheir PDF pages without having to deal with complex layout issues.\n\n### Key Features\n\n- **Predefined Page Layout**: Includes built-in base HTML and CSS to help\n structure your PDF pages efficiently.\n\n- **Flexible PDF Content and Styling**: Easily create your own HTML template for\n the PDF document and customize the appearance by applying your own CSS.\n\n- **PDF View Response Options**: Seamlessly switch between viewing the PDF,\n displaying the HTML content, and downloading the PDF file.\n\n## Prerequisites\n\n- [wkhtmltopdf](https://wkhtmltopdf.org/)\n\n## Installation\n\n```bash\npip install django-pdf-view\n```\n\nor\n\n```bash\npoetry add django-pdf-view\n```\n\n## Configuration\n\nAdd `django-pdf-view` to your `INSTALLED_APPS` in `settings.py`:\n\n```python\nINSTALLED_APPS = [\n ...\n 'django_pdf_view',\n ...\n]\n```\n\n## Usage\n\nIn order to create your own PDF, you need to implement your own view and\ntemplate.\n\n1. Create a new view to render the PDF:\n\n ```python\n # my_app/views.py \n \n from django_pdf_view.views.pdf_view import PDFView\n \n \n class MyPDFView(PDFView):\n template_name = 'my_app/my_pdf.html'\n title = 'My PDF Document' # optional\n filename = 'My PDF.pdf' # optional\n css_paths = [ # optional\n 'my_pdf/css/my_pdf.css',\n ]\n ```\n\n2. Create a new template to define the content of your PDF page:\n\n ```html\n <!-- my_app/templates/my_app/pdf_page.html -->\n \n <div class=\"page\">\n <h1 class=\"my-title\">{{ title }}</h1>\n <p class=\"my-text\">{{ text }}</p>\n <p class=\"my-text\">Additional PDF page text.</p>\n </div>\n \n <!-- Define more <div class=\"page\"> elements for additional pages -->\n ```\n\n3. Add the new URL patterns to your project's `urls.py`:\n\n ```python\n # my_app/urls.py \n \n from django.urls import path\n from my_app.views import MyPDFView\n \n urlpatterns = [\n path('pdf-file/', MyPDFView.as_view(response_type='pdf'), name='pdf-file'),\n path('pdf-html/', MyPDFView.as_view(response_type='html'), name='pdf-html'),\n path('pdf-download/', MyPDFView.as_view(response_type='download'), name='pdf-download'),\n ]\n ```\n <br/>\n\n4. Visit the belows listed URLs:\n\n- To view the PDF\n file: [http://localhost:8000/pdf-file/](http://localhost:8000/pdf-file/)\n- To view the\n HTML: [http://localhost:8000/pdf-html/](http://localhost:8000/pdf-html/)\n- To download the PDF\n file: [http://localhost:8000/pdf-download/](http://localhost:8000/pdf-download/)\n\n### Default template context\n\n- PDF document:\n - `title`: Title of the PDF document (used in `<title>` tag).\n - `css`: Content of the CSS files specified in the `css_paths` attribute.\n - `content`: Content of the HTML template.\n - `response_type`: Type of the response (`pdf`, `html` or `download`).\n\n### `svg` template tag\n\n`svg` template tag is provided by the `django-pdf-view` package. This template\ntag can be used to include SVG images in the PDF document.\n\n**Usage example**:\n\n```html\n{% load svg %}\n\n<!-- Some HTML content -->\n\n{% svg 'path/to/image.svg' %}\n\n<!-- Some more HTML content -->\n```\n\n## Bugs/Requests\n\nIf you encounter any bugs or have any requests, please use\n[GitHub issue tracker](https://github.com/roknicmilos/django-pdf-view/issues)\nto report them.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Django app for seamlessly displaying and downloading PDF documents in browser",
"version": "2.2.0",
"project_urls": {
"documentation": "https://github.com/roknicmilos/django-pdf-fixtures/blob/main/README.md",
"homepage": "https://github.com/roknicmilos/django-pdf-view",
"issues": "https://github.com/roknicmilos/django-pdf-view/issues",
"repository": "https://github.com/roknicmilos/django-pdf-fixtures/"
},
"split_keywords": [
"pdf",
" pdf view",
" django pdf",
" django pdf view",
" generate pdf",
" django generate pdf"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3a9624a36cdf2a0d25af6abc198a60828356440160907954ec28aaa2307541e4",
"md5": "d63859e0deea5aeeba356f97bff29975",
"sha256": "97d70e98895f52dbc32f896a67026c9786074057fabf1cf95f3da357ca38b310"
},
"downloads": -1,
"filename": "django_pdf_view-2.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d63859e0deea5aeeba356f97bff29975",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 13829,
"upload_time": "2024-09-22T10:58:57",
"upload_time_iso_8601": "2024-09-22T10:58:57.352552Z",
"url": "https://files.pythonhosted.org/packages/3a/96/24a36cdf2a0d25af6abc198a60828356440160907954ec28aaa2307541e4/django_pdf_view-2.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "62912a1c7b9a63a836fdeff919b86e834c86af68ed6126af84ba7fd8df7f2868",
"md5": "47517578d58eef41fcac6d034ee433f0",
"sha256": "5b8d9442c02026ccc03321915d504289d85ce4842e06e0c999876aac4ba104b4"
},
"downloads": -1,
"filename": "django_pdf_view-2.2.0.tar.gz",
"has_sig": false,
"md5_digest": "47517578d58eef41fcac6d034ee433f0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 11180,
"upload_time": "2024-09-22T10:58:58",
"upload_time_iso_8601": "2024-09-22T10:58:58.682215Z",
"url": "https://files.pythonhosted.org/packages/62/91/2a1c7b9a63a836fdeff919b86e834c86af68ed6126af84ba7fd8df7f2868/django_pdf_view-2.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-22 10:58:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "roknicmilos",
"github_project": "django-pdf-fixtures",
"github_not_found": true,
"lcname": "django-pdf-view"
}