fpdf - going back to the previous page

后端 未结 8 2494
生来不讨喜
生来不讨喜 2021-02-10 15:45

I am generating pdf invoice using fpdf.

Some invoices containing many items, and details need to go into the second page. However, I need the total, and other details

相关标签:
8条回答
  • 2021-02-10 16:12

    Just a simple "hack", but data needs to be ordered by page number (not very difficult^ ^ )

    Put in your "for loop" placing data something like :

    // ensure we are on the good page, but fields HAVE TO be ordered by page number
    while($this->fpdf->PageNo() != $myData->getPage()){
        $this->fpdf->AddPage();
    }
    

    And you are done ! No need to alter FPDF :D

    0 讨论(0)
  • 2021-02-10 16:13

    I had the same issue and I overrode a few methods of the FPDF class and was able to fix it in a fairly simple manner. In order to go back and forth pages, you simply need to change the page attribute of the FPDF object. However, once you go back a page, when you progress to the next page, you'll end up adding a new page instead of progressing to the already existing one. To deal with this issue, I created a boolean called add_new_page, and used it in my rewritten accept_page_break method to see whether or not to create a new page or progress to an already existing one.

    def prev_page(self):
        self.page -= 1
        self.add_new_page = False
    
    def next_page(self):
        self.page += 1
    
    def accept_page_break(self):
        "Accept automatic page break or not"
        if self.add_page:
            return self.auto_page_break
        else:
            self.page += 1
            self.add_new_page = True
    
    0 讨论(0)
提交回复
热议问题