Skip to main content

A simple django app for creating pdf files.

Project description

Django Phantom PDF
==================

A simple django app that takes the pain out of rendering PDFs from django views.

Quick start
-----------

1. Install node and phantomjs:

### On Mac OSX:

brew install node npm
npm install -g phantomjs

### On Ubuntu:

apt-get install node npm
sudo npm install -g phantomjs


2. Install django-phantom-pdf:

pip install django-phantom-pdf

3. That's it, you can now start using it in your django views like so and rendering PDFs!

from phantom_pdf import render_to_pdf
from django.http import HttpResponse

def home(request):
# If 'print=pdf' in GET params, then render the PDF!
if request.GET.get("print", None) == "pdf":
basename = 'output' # `.pdf` will be appended to this string.
return render_to_pdf(request, basename)
# If you want to change default format and orientation for this view
# return render_to_pdf(request, basename, format='A3', orientation='portrait')
else:
return HttpResponse("Hello World!")

Advanced Use
------------

For more advanced use and control, you can set the following variables in your setting.
They are already set to sane defaults, so it's not necessary unless you are looking for
more fine grained control.

PHANTOMJS_COOKIE_DIR = Directory where the temp cookies will be saved.
PHANTOMJS_PDF_DIR = Directory where you want to the PDF to be saved temporarily.
PHANTOMJS_BIN = Path to PhantomsJS binary.
PHANTOMJS_GENERATE_PDF = Path to generate_pdf.js file.
keep_pdf_files = Option to not delete the PDF file after rendering it.
PHANTOMJS_FORMAT = Page size to use
PHANTOMJS_ORIENTATION = How the page will be positioned when printing.

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

django-phantom-pdf-0.3.tar.gz (8.2 kB view details)

Uploaded Source

File details

Details for the file django-phantom-pdf-0.3.tar.gz.

File metadata

File hashes

Hashes for django-phantom-pdf-0.3.tar.gz
Algorithm Hash digest
SHA256 54237e55c728765623c33f9d8c394653d2bbc48d6ed4cbfa8481610a5eab21a6
MD5 4f19df3ea87499b91447bdd393cba2eb
BLAKE2b-256 3ceb5c536d1d650032db2dffd6fa1a7c7c4b877fd2a5b02bd0fcbd77e096d1d3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page