Search code examples
linefpdf

How can I draw a line over all pages in fpdf


Just as I ask in the title, how can I draw a line over all pages using fpdf?

I tried giving the line a height of 9000, but this only gave a line to the full first page, but not on any other pages.

Anyone knows how I can solve this? Thanks!


Solution

  • In FPDF, the header method is called automatically when a new page is created. From the API:

    This method is used to render the page header. It is automatically called by AddPage() and should not be called directly by the application. The implementation in FPDF is empty, so you have to subclass it and override the method if you want a specific processing.

    Here's the steps you take:

    1. Ensure that your PDF class extends FPDF's
    2. Override the header method in your extension
    3. Add your line-drawing code to the header method.

    This is the simplest solution. No keeping track of whenever a new page is added. FPDF does it automatically, so build off of their API to achieve your goal.