laravelphp-8fpdi

Debugging FPDF invalid call after upgrading laravel and PHP8


I have a web app that used FPDI to create pdf files, using laravel 5.7, setasign/fpdi-fpdf ^2.0 and PHP 7.4. I recently upgraded to laravel 9 (also upgrading respective dependencies) and because the meta package was depcrecated, I now use "setasign/fpdf": "^1.8", "setasign/fpdi": "^2.0" as well as PHP 8.0.26

Now when trying to run my script I get the error "FPDF Error: Invalid Call" with the whole trace in the error handler, but I find this error message only semi informative. Any ideas how I can debug this error? Does FPDI have issues with PHP8? I didn't see any mention of that in the documentation.

thanks in advance!


Solution

  • From FPDF code, the error is shown when state == 1

    fpdf.php#L1458

    protected function _out($s)
    {
        // Add a line to the current page
        if($this->state==2)
            $this->pages[$this->page] .= $s."\n";
        elseif($this->state==0)
            $this->Error('No page has been added yet');
        elseif($this->state==1)
            $this->Error('Invalid call');
        elseif($this->state==3)
            $this->Error('The document is closed');
    }
    

    And state 1 is when the page ends

    fpdf.php#L1128

    protected function _endpage()
    {
        $this->state = 1;
    }
    

    Which happens when you close the document by calling output() (and when you switch to the next page but that automatically opens the next page).

    So you might also have to read the new documentation of FPDF and adapt the code related to it.