Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paginating in Pisa (xhtml2pdf) just repeats last page

I am using Pisa to produce a PDF file with pages that follow a common format. I am clearly doing something wrong as when I generate the PDF (either from from the command line or from the python API) I only ever see the last page repeated.

Running the Pisa on the code below, I get three pages that each say "C Wednesday", when I'd expect to see three different pages with "A Monday", "B Tuesday", "C Wednesday".

My current version of Pisa is XHTML2PDF/pisa 3.0.33 (Build 2010-06-16)

<html>
<style>
    /* 297 x 210 */
@page {
  size: a4 landscape;
  margin: 1cm;
  margin-bottom: 2.5cm;

  @frame header {
    -pdf-frame-content: headerContent;
    background-color:black;
    color:white;
    top : 0cm;
    margin-left: 0cm;
    margin-right: 14.5cm; 
    height: 2.5cm;
    width: 14.9cm;
  }

  @frame lhs {
    -pdf-frame-content: lhs;
    background-color:white;
    color:black;
    top : 4.5cm;
    margin-left: 0cm;
    margin-right: 14.5cm; 
    height: 13.5cm;
    width: 14.9cm;
  }

  @frame footer {
    -pdf-frame-content: footerContent;
    color:black;
    bottom: 1cm;
    margin-left: 1cm;
    margin-right: 24.5cm; 
    height: 1cm;
  }

}

body {
}

#headerContent {
    text-align: center;
    background-color: black;
    color: white;
}
h1 {
    font-size: 200%;
}

#lhs-table {
    color:black;
    text-align: center;
    font-size:600%;
}

.big {
    font-size:200%;
    font-style:italic;
}

.day {
    text-align: center;
    background-color: black;
    color: white;
    width: 1.6cm;
    height: 1.3cm;
}

#footerContent {
    font-size: 200%;
}


</style>
<body>

<div>
  <div id="headerContent">
      <h1><br/>HEADER<br/></h1>
  </div>

  <div id="lhs">
      <table id="lhs-table" >
                <tr>
                    <td><span class="big"><em>A</em></span></td>
                </tr>
            </table>
    </div>

  <div id="footerContent">
      <span class="day" >Monday</span>
  </div>

  </div>
    <pdf:nextpage />


<div>
  <div id="headerContent">
      <h1><br/>HEADER<br/></h1>
  </div>

  <div id="lhs">
      <table id="lhs-table" >
                <tr>
                    <td><span class="big"><em>B</em></span></td>
                </tr>
            </table>
    </div>


  <div id="footerContent">
      <span class="day" >Tuesday</span>
  </div>

  </div>
    <pdf:nextpage />


<div>
  <div id="headerContent">
      <h1><br/>HEADER<br/></h1>
  </div>

  <div id="lhs">
      <table id="lhs-table" >
                <tr>
                    <td><span class="big"><em>C</em></span></td>
                </tr>
            </table>
    </div>

  <div id="footerContent">
      <span class="day" >Wednesday</span>
  </div>

  </div>
    <pdf:nextpage />


</body>
</html>
like image 512
ChrisGuest Avatar asked Nov 04 '22 10:11

ChrisGuest


1 Answers

Try version from Github https://github.com/chrisglass/xhtml2pdf Your version is too old and unmaintained.

About your problem, is a known problem in the parser. Try to put the tag on its own line like this:

<div id="footer">
     <pdf:pagenumber />
</div>

AFTER THIRD READING:

<body>
<div id="header">
</div>

 <div id="content1>
   content 1
 </div>
 <pdf:nextpage />

 <div id="content2>
     content 2
 </div>
 <pdf:nextpage />

 <div id="content3>
     content 3
 </div>
 <pdf:nextpage />

<div id="footer">
</div>
</body>

From your code, you are repeating header and footer for each content. But you have defined them as header frames (automatically repeat them on each page), so the parser must be going nuts. Also you are creating another static frame for content, which shouldn't be.

So, only one header, one footer, create many contents with <pdf:nextpage /> behind.

https://github.com/chrisglass/xhtml2pdf/blob/master/doc/usage.rst

Maybe I've undersrtood you wrong again, cause I don't know how are you generating this html.

like image 139
n3storm Avatar answered Nov 08 '22 04:11

n3storm