drgarcia1986 / drf-pdf

A simple PDF utils for Django Rest Framework
MIT License
25 stars 9 forks source link

Render PDF by "render template". #13

Open drgarcia1986 opened 9 years ago

drgarcia1986 commented 9 years ago

http://weasyprint.org/docs/

drgarcia1986 commented 9 years ago

Example

from weasyprint import HTML

class FromTemplate(APIView):
    renderer_classes = (PDFRenderer, )

    def get(self, request):
        pdf = StringIO()

        # This example may change to a new drf-pdf response
        HTML(string='<h1>Foo</h1>').write_pdf(pdf)

        return PDFResponse(
            pdf.getvalue(),
            file_name='example',
            status=status.HTTP_200_OK
        )
iamkhush commented 8 years ago

We could do this using render_to_string (from django.template.loader)

May I know what are you trying to achieve here?