How to add header and footer to a PDF file by rendering HTML page

584 Views Asked by At

I have generated a pdf file by rendering an HTML page. Here is what i did for that

return render_to_pdf(                
                html,
            )


def render_to_pdf(html):
    result = StringIO.StringIO()
    pdf = pisa.pisaDocument(StringIO.StringIO(html.encode('utf-8') ),  
              dest=result)
    if not pdf.err:
        return HttpResponse(result.getvalue(), 
              content_type='application/pdf') 

So this will give me a pdf file against the inputted HTML file.

I want to add header and footer for this pdf file , is there any way that i can do this dynamically. Dynamically in the sense for the first page in the pdf i need a footer and in the second page i need another footer that will be different from the first one, and in other page may have different footer so and so. So is there any way that i can include such feature in this, by specifying the page number. Any help would be greatly appreciated.

0

There are 0 best solutions below