Giter VIP home page Giter VIP logo

django-xhtml2pdf's Introduction

Django xhtml2pdf

Attention

This project is wrapper code between the django project and the xhtml2pdf project, both have a few maintaining so maybe are not ideal for your project.

Please get in touch if you would like to take over maintainership.

What it does is simply allow people to create xhtml2pdf templates using all the cool django things like STATIC_URL etc.. (like one would for a webpage template), and the utils function makes all the images and ressources appear in the pdf.

Usage

Simply do the following:

from django_xhtml2pdf.utils import generate_pdf

def myview(response):
    resp = HttpResponse(content_type='application/pdf')
    result = generate_pdf('my_template.html', file_object=resp)
    return result

Class-based views

You can use the provided PdfMixin with any view that subclasses TemplateView, example:

from django.views.generic.detail import DetailView
from django_xhtml2pdf.views import PdfMixin
from .models import Product

class ProductPdfView(PdfMixin, DetailView):
    model = Product
    template_name = "product_pdf.html"

It will output the rendered content of the view in pdf.

Decorator

Simply do the following:

from django_xhtml2pdf.utils import pdf_decorator

@pdf_decorator
def myview(request):
    return render(request, 'mytemplate.html')

Change de pdf file name:

from django_xhtml2pdf.utils import pdf_decorator

@pdf_decorator(pdfname='new_filename.pdf')
def myview(request):
    return render(request, 'mytemplate.html')

django-xhtml2pdf's People

Contributors

luisza avatar chrisglass avatar vierno avatar beniwohli avatar cro avatar xgvargas avatar jensadne avatar ojii avatar yuce 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.