Fpdf - return to previous page

I am creating a pdf account using fpdf.

Some invoices containing many items and details need to go to the second page. However, I need general and other details that will be displayed on the first page.

Right now, if I can add a new page as follows: $ Pdf-> AddPage ();

But this puts everything on the second page, regardless of this statement.

There seems to be no way to specify a page for recording methods or cells.

Rendering, and bit calculations are complicated, so you do not need to store temp in the array and display after the full rendering of the first page.

Thanks.

+3
source share
8 answers
if(!empty($this->replace) && !empty($this->replacement)){
    $this->pages[$n]=str_replace($this->replace,$this->replacement,$this->pages[$n]);
}

fpdf _putpages() / 2851

:

$pdf->replace = array("{paid_msg}","{balance}");
$pdf->replacement = array("Paid","0.00");

.

+2

, :

function SetPage($num) {
    $this->page = $num;
}

, . , , , Cell(). :

    if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak())

AcceptPageBreak , , , , . , , , , . ADDING , Y . :

if ($this->page < count($this->pages)) {
        $this->SetPage(($this->page)+1);
        $this->y = .5;
    }

FPDF, , , script . , , , script, .

+4

FPDF . - AddPage(), SetAutoPageBreak(), .

, , , ( FPDI: http://www.setasign.de/products/pdf-php-solutions/fpdi/) .

+3

, , FPDF , , .

!

, - , . . ( PDF).

0

* str_replace * - "n m ". n , , , , , m- $pdf- > [$ i] .

0

, , , . Y Y, , , .

" " , ($pdf->PageNo()) Y ($pdf->GetY()).

. " ", . -, " ", . , Y , .

, .

X- .

public function GetVerticalPosition() {
  // Include page and Y position of the document
  return array(
    'page' => $this->PageNo(),
    'y' => $this->GetY(),
  );
}

public function SetVerticalPosition( $pos ) {
  // Set the page and Y position of the document
  $this->page = $pos['page'];
  $this->SetY( $pos['y'] );
}

public function FurthestVerticalPosition( $aPos, $bPos = null ) {
  if ( $bPos === null ) $bPos = $this->GetVerticalPosition();

  // Returns the "furthest" vertical position between two points, based on page and Y position
  if ( 
    ($aPos['page'] > $bPos['page']) // Furthest position is located on another page
    ||
    ($aPos['page'] == $bPos['page'] && $aPos['y'] > $bPos['y'] ) // Furthest position is within the same page, but further down
  ) {
    return $aPos;
  }else{
    return $bPos;
  }
}

. , .

$startPos = $this->GetVerticalPosition();
$furthestPos = $this->GetVerticalPosition();

, , ( ), .

// Returns the furthest of the two possibilites
$furthestPos = $this->FurthestVerticalPosition( $this->GetVerticalPosition(), $furthestPos );
$this->SetVerticalPosition( $startPos );

, , .

$this->SetVerticalPosition( $furthestPos );

, .

0

, FPDF . , FPDF. , , , . , add_new_page accept_page_break, , .

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

"", ( ^ ^)

"for loop", :

// 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're done! No need to change FPDF: D

0
source

Source: https://habr.com/ru/post/1720817/


All Articles