Beispiel #1
0
def create_pdf_response(document):
    # Create Buffer
    buff = BytesIO()

    # Build template
    template = BriefTemplate(buff, document)
    template.build(document.content)

    # Create Response and close Buffer
    response = HttpResponse(content_type='application/pdf')
    response['Content-Disposition'] = \
        'attachment; filename="uebermittlungssperre.pdf"'

    pdf_response = buff.getvalue()
    buff.close()
    response.write(pdf_response)

    return response
    def pdf_response(self):
        # create document structure
        document = Document(
            sender = self.sender_address,
            recipient = self.recipient_address,
            date = datetime.datetime.now().strftime("%d.%m.%Y"),
            content = self._content()
        )

        # create response instance
        response = HttpResponse(content_type='application/pdf')
        filename = "dsg-2000-auskunft-" + self.sender_name.replace(' ','-').lower() + ".pdf"
        response['Content-Disposition'] = \
            'attachment; filename="' + filename + '"'

        # build letter template
        buff = BytesIO()
        template = BriefTemplate(buff, document)
        template.build(document.content)
        pdf_response = buff.getvalue()
        buff.close()

        response.write(pdf_response)
        return response