Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django pdf: page layout with long texts using pisa

Tags:

django

pisa

I use pisa to generate some PDF files of the following layout:

  @page {
        size: a4;
        @frame header {
          top: 5.4cm;
          bottom: 4cm;
          left: 1.2cm;
          right: 1.2cm;
        }
        @frame main {
          top: 10.5cm;
          bottom: 4cm;
          left: 1.2cm;
          right: 1.2cm;
        }
        @frame footer {
          top: 26cm;
          left: 1.2cm;
          right: 1.2cm;
        }
      }

Sometimes the content of the main frame is not short enough to fit in a single page and so it uses the space of the footer frame as well. Instead of that, I would like to have the rest of the text in the main's frame space of the second page (and keep the space of the rest frames clear). Any suggestions?

like image 923
Kassandra Avatar asked Dec 28 '22 14:12

Kassandra


1 Answers

Pisa is not particularly easy to figure out. I use it to generate several different formats of reports.

I do not put my main content within a frame. Also it's all in inches/letter sized, but I want to give you exactly how mine is setup, and works for multiple pages.

Your problem may be fixed by adding margin to the @page or <keepinframe></keepinframe> tags.

<document pagesize='letter'>
<head>
    <title>{{ title }}</title>
    <style type="text/css">
        @page {
            size: letter portrait;
            margin: 1.0in 0.25in 0.5in 0.25in;
            padding: 0;

            @frame header {
                -pdf-frame-content: headerContent;
                width: 8in;
                top: 0.5in;
                margin-left: 0.5in;
                margin-right: 0.5in;
                height: 1.0in;
            }
            @frame footer {
                -pdf-frame-content: footerContent;
                width: 8in;
                bottom: 0in;
                margin-left: 2cm;
                margin-right: 2cm;
                height: 1cm;
            }
        } <!-- end of @page bracket -->

        <!-- add content styles here -->
        h1 { text-align: middle; font-size: 18px; }
    </style>
</head>
<body>
<div id='headerContent'>
    <!-- header content -->
</div>
<div>
    <keepinframe>
     <!-- Content -->
    </keepinframe>
</div>
<div id='footerContent'>
    <!-- footer content -->
    <pdf:pagenumber>
</div>
</body>
</document>
like image 140
j_syk Avatar answered Jan 07 '23 22:01

j_syk