Giter VIP home page Giter VIP logo

django-phantom-pdf's Introduction

This package is deprecated and no longer maintained.

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
  1. Install django-phantom-pdf:

     pip install django-phantom-pdf
    
  2. 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, orientation and margins for this view
             # return render_to_pdf(request, basename, format='A3', orientation='portrait', margin={'top': '4.5cm'})
         else:
     	    return HttpResponse("Hello World!")
    

Advanced Use

For more advanced use and control, you can set the following variables in your settings. 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.
PHANTOMJS_MARGIN = The margins of the PDF.

django-phantom-pdf's People

Contributors

edvm avatar jcarizza avatar ssebastianj avatar toabi avatar tzenderman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.