2017-03-12 5 views
1

FPDFを使用してレポートを作成しようとしています。ベローコードは非常にうまくレポートを生成しますが、今はすべてのページでテーブルヘッダーセクションを繰り返す必要があります。また、ヘッダーとフッターに余白を追加する方法もあります。現在のところロゴセクションのみが繰り返されています。会社名のロゴと表のヘッダーを含む完全なセクションを繰り返す方法。ここでfpdfを使用してページ区切りにヘッダーを繰り返す方法

は、私のテーブルのヘッダーセクションである:

$pdf->SetFillColor(170, 170, 170); //gray 
    $pdf->setFont("Arial","B","9"); 
    $pdf->setXY(10, 40); 
    $pdf->Cell(25, 10, "Payorder Date", 1, 0, "L", 1); 
    $pdf->Cell(35, 10, "Payorder Number", 1, 0, "L", 1); 
    $pdf->Cell(50, 10, "Beneficiary Name", 1, 0, "L", 1); 
    $pdf->Cell(30, 10, "Contra Date", 1, 0, "L", 1); 
    $pdf->Cell(30, 10, "Amount", 1, 0, "L", 1); 

ここに私の完全なコードです:

<?php 
$localhost = 'localhost'; //name of server. Usually localhost 
$database = 'payorder'; //database name. 
$username = 'root'; //database username. 
$password = ''; //database password. 

// connect to db 
$conn = mysql_connect($localhost, $username, $password) or die('Error connecting to mysql'); 
$db = mysql_select_db($database,$conn) or die('Unable to select database!'); 

     require('lib/include/fpdf/fpdf.php'); 
      class PDF extends FPDF { 
       //Page header 
       function Header(){ 
        //Logo 
        $this->Image('images/logo.jpg',15,8,20); 

       } 
       //Page footer 
       function Footer(){ 
        //Position at 1.5 cm from bottom 
        $this->SetY(-15); 
        //$this->SetX(-35); 
        //Arial italic 8 
        $this->SetFont('Arial','I',8); 

        //Page number 
        $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C'); 
       } 
      } 

      $pdf = new PDF(); 
      //$pdf->open(); 
      $pdf->AddPage("P","A4"); // P =portrait L = Landscape 
      $pdf->AliasNbPages(); // necessary for x of y page numbers to appear in document 
      $pdf->SetAutoPageBreak(true, 20); 

      // document properties 
      $pdf->SetAuthor('Sonali Bank Limited'); 
      $pdf->SetTitle('Daily Transuction Report'); 

      $pdf->SetFont('Arial','B',14); 
      $pdf->Cell(30,10,' Company name Here'); 

      // Add date report ran 
      $pdf->SetFont('Arial','I',10); 
      $date = date("d/m/Y"); 
      $pdf->Cell(20,20,"Company Subtitle here Dated: ".$date); 
      $pdf->SetDrawColor(0, 0, 0); //black 

      //table header 
      $pdf->SetFillColor(170, 170, 170); //gray 
      $pdf->setFont("Arial","B","9"); 
      $pdf->setXY(10, 40); 
      $pdf->Cell(25, 10, "Payorder Date", 1, 0, "L", 1); 
      $pdf->Cell(35, 10, "Payorder Number", 1, 0, "L", 1); 
      $pdf->Cell(50, 10, "Beneficiary Name", 1, 0, "L", 1); 
      $pdf->Cell(30, 10, "Contra Date", 1, 0, "L", 1); 
      $pdf->Cell(30, 10, "Amount", 1, 0, "L", 1); 

      $y = 50; 
      $x = 10; 
      $pdf->setXY($x, $y); 
      $pdf->setFont("Arial","","9"); 

      //payorder data query 
      $sql = "SELECT * FROM payorder_data WHERE po_date ='$report_day'"; 
      $res = mysql_query($sql) or die(mysql_error()); 
      $row = mysql_num_rows($res); 
      while($row = mysql_fetch_array($res)){ 
        $pdf->Cell(25, 8, $row['po_date'], 1); 
        $pdf->Cell(35, 8, $row['po_number'], 1); 
        $pdf->Cell(50, 8, $row['po_ben_name'], 1); 
        $pdf->Cell(30, 8, $row['contra_date'], 1); 
        $pdf->Cell(30, 8, $row['po_amount'], 1); 
        $y += 8; 

        if ($y > 260) // When you need a page break 
        { 
         $pdf->AddPage(); 
         $y = 40; 
        } 
        $pdf->setXY($x, $y); 
       } 
      $pdf->Output(); 
      } 
+0

データセットを配列またはjsonとして提供できるかどうかは、 –

+0

@ARIFMAHMUDRANAにありがとうございます。 Arif https://www.dropbox.com/s/p6iwdcdsiskdy2k/payorder.sql?dl=1こちらはSQL – Firefog

+0

質問コードが更新された – Firefog

答えて

1

あなたは、このセクション

if ($y > 260) // When you need a page break 
    { 
    $pdf->AddPage(); 
    $y = 40; 
    } 

にあなたのコードを変更する必要があります何かを作りますこの

if ($y > 260) // When you need a page break 
    { 
     $pdf->AddPage(); 
     $pdf->SetFillColor(170, 170, 170); //gray 
     $pdf->setFont("Arial","B","9"); 
     $pdf->setXY(10, 40); 
     $pdf->Cell(25, 10, "Payorder Date", 1, 0, "L", 1); 
     $pdf->Cell(35, 10, "Payorder Number", 1, 0, "L", 1); 
     $pdf->Cell(50, 10, "Beneficiary Name", 1, 0, "L", 1); 
     $pdf->Cell(30, 10, "Contra Date", 1, 0, "L", 1); 
     $pdf->Cell(30, 10, "Amount", 1, 0, "L", 1); 

     $y = 50; 
     $x = 10; 
     $pdf->setXY($x, $y); 
     $pdf->setFont("Arial","","9"); 
    } 

と同じように編集:下マージンのためのよう

あなたのマージンを設定するために、あなたはこのマニュアルのhttp://www.fpdf.org/en/doc/setmargins.htm

でドキュメントを見てみることができ、それは、下のマージンが含まれていませんこの記事をご覧ください:How to set a bottom margin in FPDF

このようなマージンを設定することもできます

$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); 
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER); 
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER); 
+0

ありがとうございます。私はこれを試してみる – Firefog

関連する問題