Start first PDF page a certain distance from top then start at the top on every page after that?

251 views Asked by At

Using XHTMLPDF2 in Python; great tool!

I'm generating PDFs to integrate into yet another PDF, so I need the first page to start at a certain height from the top (say 432pt at times, 200pt at others; it's in a variable).

Every page after that, however, should start at the top.

I've tried this CSS, and it works just like I want it to... except the the second pages and onwards start by writing over the first one and you get this mesh of the original first page with the second page starting on the first. Every other page is fine.

Here's my style :

<style>
    @page {
    size: letter landscape;
    @frame content1_frame {left: 50pt; width: 512pt; top: 494pt; height: 118pt;}
    @frame content2_frame {left: 50pt; width: 512pt; top: 20pt; height: 612pt;}
    }
</style>

I've also tried using just one frame (content1_frame only) but every page starts 494pt from the top. Thanks in advance

1

There are 1 answers

0
Miguel Diaz On

Just before your content, use

<pdf:spacer height="400px">

So your source HTML might look like

<html><head><style>
    @page {
    size: letter landscape;
    @frame content2_frame {left: 50pt; width: 512pt; top: 20pt; height: 612pt;}
    }
</style>
</head><body>
<pdf:spacer height="400px">
    My exciting content goes here! <span style="font-family: Verdana, Arial; font-size: 13.3999996185303px; line-height: 19.1428565979004px; text-align: center; background-color: #ccccdd;">T</span>
</body></html>

And your Python code

from xhtml2pdf import pisa             # import python module
resultFile = open('out.pdf', "w+b")
pisaStatus = pisa.CreatePDF(sourceHTML, dest=resultFile)
resultFile.close()