Skip to main content
# DRF-PDF
[![Documentation Status](https://readthedocs.org/projects/drf-pdf/badge/?version=latest)](https://readthedocs.org/projects/drf-pdf/?badge=latest)
[![Build Status](https://travis-ci.org/drgarcia1986/drf-pdf.svg?branch=master)](https://travis-ci.org/drgarcia1986/drf-pdf)
[![Coverage Status](https://coveralls.io/repos/drgarcia1986/drf-pdf/badge.svg)](https://coveralls.io/r/drgarcia1986/drf-pdf)
[![Code Health](https://landscape.io/github/drgarcia1986/drf-pdf/master/landscape.svg?style=plastic)](https://landscape.io/github/drgarcia1986/drf-pdf/master)

A simple PDF utils for Django Rest Framework

## Install

```
pip install drf-pdf
```

## Example

```python
# coding: utf - 8
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView

from drf_pdf.renderer import PDFRenderer

from my_pdf_package import PDFGenerator


class PDFHandler(APIView):

renderer_classes = (PDFRenderer, )

def get(self, request):
pdf = PDFGenerator('foo')
headers = {
'Content-Disposition': 'filename="foo.pdf"',
'Content-Length': len(pdf),
}

return Response(
pdf,
headers=headers,
status=status.HTTP_200_OK
)
```

### With two or more renderer_classes


```python
# coding: utf - 8
from rest_framework import status
from rest_framework.response import Response
from rest_framework.renderers import JSONRenderer
from rest_framework.views import APIView

from drf_pdf.response import PDFResponse
from drf_pdf.renderer import PDFRenderer

from my_pdf_package import get_pdf


class PDFHandler(APIView):

renderer_classes = (PDFRenderer, JSONRenderer)

def get(self, request, pdf_id):
pdf = get_pdf(pdf_id)
if not pdf:
return Response(
{'error': 'Not found'},
status=status.HTTP_404_NOT_FOUND
)

return PDFResponse(
pdf=pdf,
file_name=pdf_id,
status=status.HTTP_200_OK
)
```

Download files

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

Source Distribution

drf-pdf-0.2.0.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file drf-pdf-0.2.0.tar.gz.

File metadata

  • Download URL: drf-pdf-0.2.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for drf-pdf-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4e870bff87d19f43fa0bb85f8112ab0588db0c7bb00656f1ec52120d19ac4b2a
MD5 d0b83be45c58750f659be2fab9fe5c32
BLAKE2b-256 007565c7f9120e197e142ae0f65aa6d5fecb649a349a1ea36e2ba20db6cb90bc

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 file

0.1.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page