Giter VIP home page Giter VIP logo

django-pdf's Introduction

django-pdf

A django MiddleWare to converte on-the-fly views' HTML output to PDF without modifying your views.

About

Django-pdf use xhtml2pdf to tranform the HtmlResponce object to pdf.

It's still under development and need testing ,bug report, feature request, coding, ...

Usage

Simply add ?format=pdf to your url to get the pdf version of the page.

You can add a pdfname option to your url to specify a name for the generated pdf (without extension). Remember to urlencode pdfname. / chars are automatically converted to -.

Install

get sources

git clone https://github.com/bisio/django-pdf cd django-pdf cp django_pdf to your project or in your PYTHON_PATH

** pip install will come **

requirement

http://github.com/chrisglass/xhtml2pdf/

settings.py

  1. add 'django_pdf' to INSTALLED_APPS
  2. add 'django_pdf.middleware.PdfMiddleware' to MIDDLEWARE_CLASSES
  3. check that TEMPLATE_CONTEXT_PROCESSORS content is
("django.core.context_processors.auth",
 "django.core.context_processors.debug",
 "django.core.context_processors.i18n",
 "django.core.context_processors.media",
 "django.core.context_processors.request")
  1. and add "django_pdf.context_processors.check_format",before )

Configuration

You can customize in your settings.py

  • REQUEST_FORMAT_NAME (default is 'format')
  • REQUEST_FORMAT_PDF_VALUE (default is 'pdf')
  • TEMPLATE_PDF_CHECK (default is 'DJANGO_PDF_OUTPUT')

Template tags and variables

pdf or not pdf ?

You may ask: "Wait! what if I don't want to include some parts of the HTML page in the PDF output? (like a menu)" You'd be right, and the answer is easy: Use the variable DJANGO_PDF_OUTPUT in your template which will be set to True if the PDF is requested and to False otherwise.

Example:

{% if not DJANGO_PDF_OUTPUT %}
       <ul id="menu">
           <li>menu item</li>
           <li>menu item</li>
           <li>menu item</li>
       </ul>
{% endif %}

Also, you can use {% if DJANGO_PDF_OUTPUT %} to include some parts only in the PDF output.

direct link

You have a new template tag {{ pdf_link }} which will generate a link to the PDF version of the current page. :)

django-pdf's People

Contributors

bisio avatar directeur avatar mchccc avatar

Stargazers

Altimore avatar  avatar  avatar

Watchers

James Cloos avatar

Forkers

mchccc

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.