Problem with tcpdf Pagebreak

I have a little problem with a page error. Multicell is displayed above the footer of the first page and then broken: how can I set the bottom margin of the page so that the break occurs earlier above? Here is a PDF example: An example and here is the source code:

<?php require_once('../tcpdf/config/lang/eng.php'); 
  require_once('../tcpdf//tcpdf.php'); 

  class MYPDF extends TCPDF {
    public function Header() { 
      $auto_page_break = $this->AutoPageBreak;
      $this->SetAutoPageBreak(false,0); 
      $this->setJPEGQuality(100); $img_file = 'images/mandanten/ce_background.jpg';       
      $this->Image($img_file, $x=160, $y=72, $w=36, $h=200, $type='', $link='', $align='', $resize=true, $dpi=150, $palign='', $ismask=false, $imgmask=false, $border=0);        
      $this->SetAutoPageBreak($auto_page_break); } 
   }

 $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 
 $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('tmpAutor');  
 $pdf->SetTitle('tmpTitle'); $pdf->SetSubject('tmpSubject'); 
 $pdf->SetKeywords('tmp');   $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); 
 $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));                
 $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); 
 $pdf->SetMargins(PDF_MARGIN_LEFT, 10, PDF_MARGIN_RIGHT);                                   
 $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);  
 $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);             
 $pdf->SetAutoPageBreak(True, PDF_MARGIN_BOTTOM); 
 //set image scale factor 
 $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); 
 //set some language-dependent strings 
 $pdf->setLanguageArray($l); $pdf->AddPage(); 
 $pdf->SetFont('freesans', '', 16); 
 $pdf->Cell(0, 10, 'Headline', 0, 1, 'L'); 
 $pdf->SetFont('freesans', '', 11); 
 // Some Dummy Unicode content 
 $tmp = 'Lorèm ìpsum dolor sìt åmèt, čonsètètur sådìpsčìng èlìtr, sèd dìåm nonumy èìrmod tèmpor ìnvìdunt ut låborè èt dolorè mågnå ålìquyåm èråt, sèd dìåm voluptuå. åt vèro èos èt åččusåm èt justo duo dolorès èt èå rèbum. Stèt člìtå kåsd gubèrgrèn, no sèå tåkìmåtå sånčtus èst Lorèm ìpsum dolor sìt åmèt. Lorèm ìpsum dolor sìt åmèt, čonsètètur sådìpsčìng èlìtr, sèd dìåm nonumy èìrmod tèmpor ìnvìdunt ut låborè èt dolorè mågnå ålìquyåm èråt, sèd dìåm voluptuå. åt vèro èos èt åččusåm èt justo duo dolorès èt èå rèbum. Stèt člìtå kåsd gubèrgrèn, no sèå tåkìmåtå sånčtus èst Lorèm ìpsum dolor sìt åmèt.wåèdr';

$pdf->MultiCell(140, 0, $tmp."<br><br>".$tmp."<br><br>".$tmp."<br><br>".$tmp."<br><br>".$tmp."<br><br>".$tmp."<br><br>".$tmp."<br><br>".$tmp."<br><br>".$tmp."<br><br>".$tmp."<br><br>".$tmp, 0, 'J', 0, 0, '', '', true, 0,true);    
$pdf->Output('example_051.pdf', 'I');
+3
source share
10 answers

$ pdf-> SetFooterMargin (PDF_MARGIN_FOOTER); $ pdf-> SetAutoPageBreak (True, PDF_MARGIN_BOTTOM);

You tried:

      $pdf->SetAutoPageBreak(True, PDF_MARGIN_FOOTER);

or

      $pdf->SetAutoPageBreak(True, where_I_want_break);
+5
source

Like jason

checkPageBreak(). 5.9.113 tcpdf. changePageBreak() . , MultiCell() , , , . .

, :

while($data = mysql_fetch_assoc($result))
{
    $pdf->MultiCell(20,6,$data['date'],0,'C',0,0);
    $pdf->MultiCell(40,6,$data['refnumber'],0,'C',0,0);
    $pdf->MultiCell(66,6,$data['memo'],0,'L',0,0);
    $pdf->MultiCell(20,6,$data['linetotal']),0,'R',0,0);
    $pdf->Ln();
    if($pdf->checkPageBreak()) $pdf->Ln();
    }

checkPageBreak() true . , , .

, - MutliCell .

+3

, 6.2.0 ( , , , ). LN, - - MultiCell, ... Chance checkPageBreak . , , TCPDF " ".

, TCPDF ( , ) :

/**
 * Keep the next segment together on one page
 * @param $height (float) the height of the lines to print together
 */
public function keepTogether($height) {
    $this->checkPageBreak($height);
}

, print-each-record:

// getStringHeight ($w, $txt, $reseth=false, $autopadding=true, $cellpadding='', $border=0)
$lineHeight = $this->pdf_printer->getStringHeight(0, 'Test', false, true, '', 1);

$this->pdf_printer->keepTogether($lineHeight);

. MultiCell, . HTML, .

+2

, tcpdf, , :

    public function WriteCellText( $CellValue, $x, $y,$w, $h){

            $bMargin = $this->getBreakMargin();
            $auto_page_break = $this->AutoPageBreak;
            $this->SetAutoPageBreak(false, 0);
            $this->SetXY($x, $y, true);
            $this->Cell($w,$h, $CellValue, 0, 0, 'L', 0, '', 0, true);
            $this->SetAutoPageBreak($auto_page_break, $bMargin);
    }
+1

Ln(). checkPageBreak(). Ln():

    if (is_string($h)) {
        $this->y += $this->lasth;
    } else {
        $this->y += $h;
    }

:

    if (is_string($h))
        $h = $this->lasth;
    if (!$this->checkPageBreak($h))
       $this->y += $h;

-.

+1

, checkPageBreak, while. PHP 4. PHP5 checkPageBreak - . , , , .

, , , , addPage().

. , - .

0

writeHTMLCell MultiCell

$pdf->MultiCell(140, 0, $tmp."<br><br>".$tmp."<br><br>".$tmp."<br><br>".$tmp."<br><br>".$tmp."<br><br>".$tmp."<br><br>".$tmp."<br><br>".$tmp."<br><br>".$tmp."<br><br>".$tmp."<br><br>".$tmp, 0, 'J', 0, 0, '', '', true, 0,true); 

$this->writeHTMLCell(0, 25, 25, 250,'Footer value', 0, 0, 0, true, 'C', true);
0

TCPDF,

// Position at 15 mm from bottom
    $this->SetY(-15);
    // Set font
    $this->SetFont('helvetica', 'B', 8);
//Userdefind Function -Testing

$pg_num = $this->getPage();
$page_height = $this->getPageHeight();
$ph = $page_height;
$this->writeHTMLCell(0, 25, 25, $ph-19.4,'footer data', 0, 0, 0, true, 'C', true);
$this->writeHTMLCell(0, 25, 25, $ph-9.4,'footer data', 0, 0, 0, true, 'L', true);
0
    $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
    ...
    $pdf->SetMargins(10, 10, 10);
    $pdf->SetAutoPageBreak(true, 10);
    foreach($array as $item)
    {
        $pdf->AddPage(); //add new page for new item
        $txt = some_long_long_text;
        $pdf->Write(0, $txt, '', 0, 'C', true);
        $pdf->endPage(); //do end of page
        $pdf->lastPage(); //set cursor at last page, because autopagebreak not do it
    }

In the example, you have 10 students in an array, and you need to create a resume for each. On the exam, one resume has 3 pages. This way you get a pdf with 30 pages with the correct text.

ps Sry for my english.

0
source

A blank page is not really a real new page, because when you add a page, you are still on a white page. Therefore, after fixing the problem:

$this->pdf->AddPage('P', 'A4');
$this->pdf->deletePage($this->pdf->getNumPages());
0
source

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


All Articles