Теги <header> <body> и <footer> не работают должным образом xhtml2pdf | django

Я использую xhtml2pdf для преобразования html-страницы в pdf и хотел бы иметь верхний и нижний колонтитулы, которые повторяются на каждой новой странице. Я пытался использовать теги <header> и <footer> из html, но на самом деле они не работают: они просто появляются на странице прямо в том месте, где я написал код.

Есть идеи, в чем может быть проблема?

У меня также возникли проблемы с пагинацией: Я уже искал похожие вопросы в stackoverflow, но не смог справиться с проблемой.

Мой шаблон.html, который нужно перевести в pdf.

<!DOCTYPE html>
<style type="text/css">

    table{
        padding-top: 10px;
        border-right: 1.5px solid black;
        border-left: 1.5px solid black;

    }
    .intestazione {
        padding-top: 10px;
        border-right: 0.5px solid black;
        border-left: 0.5px solid black;
    }
 
    .vuota {
        background-color: grey;
    }
    .vuota2{
        border-top: 0px;
        border-bottom: 0px;
        border-left:0px;
        border-right:0px;
    }
    td{
        margin-left: 5px;
        border: 0.5px solid black;
    }
    th{
        border: 0.5px solid black;
    }

    .interno {
        border-top: 0.3px solid black;
        border-bottom: 0.3px solid black;
    }
    
    .center2 {
    margin: auto;
    width: 5%;
    }
    
 
</style>
<html>
    <header>
    <div class="center2">
        <table class="intestazione"> 
            <tr>
                <td rowspan="2" style="width:200px; height:200px;  padding-top:-20px; padding-bottom: -20px; padding-left: 5px"><img  src="image.png" size=100></td>
                <td style="font-size: 10px; width: 450px;"><center><b>MODULE</b></center></td>
                <td style="font-size: 10px; width:80px; height:30px"><center><b>MD74200AZ.003</b></center></td>
            </tr>
            <tr>
                <td style="font-size: 13px; font-weight: bold; width: 450px;"><center>TITLE</center></td>
                <td style="font-size: 10px;"><center>PAG. 1/6</center></td>
            </tr>
        </table>
    </div>
    </header>

    <footer>BlaBla</footer>
    <br>
    <body>
   
        <table style="border-top: 1.5px solid black">
            <tr>
                <td style="font-weight: bold;">STRUTTURA</td>
                <td>{{att.Struttura}}</td> 
                <td style="font-weight: bold;">DATA</td>
                <td>{{att.Data}}</td>
            </tr>
        </table>
        <table>
            <tr>
        <!-- etc etc -->
        </body>

Мой views.py:

def export_pdf(request, pk):
    att = MAIN.objects.get(id=pk)
   
    specs = Specifiche.objects.filter(ID_rich=pk)
    lista=[]
    for spec in specs:
        lista+=[spec.id]
    uns = Unicita.objects.filter(rifext__in=lista)
    crs = Criteri.objects.filter(ID_rich = pk)
    cons = Consumabili.objects.filter(ID_rich = pk)
    context = {'att': att, 'uns': uns, 'specs': specs, 'crs':crs, 'cons':cons}
    template = get_template('modulorichiesta.html')
    html = template.render(context)
    result = BytesIO()
    pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1", "ignore")), result)
    response = HttpResponse(result.getvalue(), content_type="application/pdf")
    filename = str(att.Protocollo) + str(timezone.now())
    content = "attachement; filename='%s'"%(filename)
    response["Content-Disposition"] = content
    return response
Вернуться на верх