2015-08-31 81 views
1

的大小我創建了我的第一個fpdf頁面,並在我的pdf內部從我的數據庫中獲取數據。一切工作到目前爲止,除了我的文件的起始高度。

請大家看我的檔案在這裏:http://schulkantine.ccsolution.at/admin/speiseplan-pdf.php

正如你可以看到它是在頂部太多。我試圖改變我目前的模板,但我無法改變這個問題。

這裏是我的代碼:

<?php 
require('../assets/fpdf17/fpdf.php'); 

//Connect to your database 
// Create connection credentials 
$db_host = 'localhost'; 
$db_name = 'DBNAME'; 
$db_user = 'DBUSER'; 
$db_pass = 'DBPASS'; 

// Create mysqli object 
$connect = new mysqli ($db_host, $db_user, $db_pass, $db_name); 

//Create new pdf file 
$pdf=new FPDF('L'); 

//Open file 
$pdf->Open(); 

//Disable automatic page break 
$pdf->SetAutoPageBreak(false); 

//Add first page 
$pdf->AddPage(); 

//set initial y axis position per page 
$y_axis_initial = 25; 

//print column titles for the actual page 
$pdf->SetFillColor(255, 0, 0); 
$pdf->SetFont('Arial', 'B', 12); 
$pdf->SetY($y_axis_initial); 
$pdf->SetX(8); 
$pdf->Cell(40, 6, 'Kalenderwoche', 1, 0, 'L', 1); 
$pdf->Cell(25, 6, 'Menueart', 1, 0, 'L', 1); 
$pdf->Cell(20, 6, 'Datum', 1, 0, 'L', 1); 
$pdf->Cell(25, 6, 'Wochentag', 1, 0, 'L', 1); 
$pdf->Cell(25, 6, 'Vorspeise', 1, 0, 'L', 1); 
$pdf->Cell(30, 6, 'Hauptspeise', 1, 0, 'L', 1); 
$pdf->Cell(25, 6, 'Nachspeise', 1, 0, 'L', 1); 

$y_axis = $y_axis + $row_height; 

//Select the Products you want to show in your PDF file 
$result=mysqli_query($connect, "Select kalenderwoche, menueart, datum, wochentag, vorspeise, hauptspeise, nachspeise FROM speiseplan ORDER BY id"); 

//initialize counter 
$i = 0; 

//Set maximum rows per page 
$max = 25; 

//Set Row Height 
$row_height = 6; 

while($row = mysqli_fetch_array($result)) 
{ 
    //If the current row is the last one, create new page and print column title 
    if ($i == $max) 
    { 
     $pdf->AddPage(); 

     //print column titles for the current page 
     $pdf->SetY($y_axis_initial); 
     $pdf->SetX(25); 
     $pdf->Cell(30, 6, 'kalenderwoche', 1, 0, 'L', 1); 
     $pdf->Cell(25, 6, 'menueart', 1, 0, 'L', 1); 
     $pdf->Cell(30, 6, 'datum', 1, 0, 'R', 1); 
     $pdf->Cell(30, 6, 'wochentag', 1, 0, 'R', 1); 
     $pdf->Cell(30, 6, 'vorspeise', 1, 0, 'R', 1); 
     $pdf->Cell(30, 6, 'hauptspeise', 1, 0, 'R', 1); 
     $pdf->Cell(30, 6, 'nachspeise', 1, 0, 'R', 1); 

     //Go to next row 
     $y_axis = $y_axis + $row_height; 

     //Set $i variable to 0 (first row) 
     $i = 0; 
    } 

    $kalenderwoche = $row['kalenderwoche']; 
    $menueart = $row['menueart']; 
    $datum = $row['datum']; 
    $wochentag = $row['wochentag']; 
    $vorspeise = $row['vorspeise']; 
    $hauptspeise = $row['hauptspeise']; 
    $nachspeise = $row['nachspeise']; 

    $pdf->SetY($y_axis); 
    $pdf->SetX(8); 
    $pdf->Cell(30, 6, $kalenderwoche, 1, 0, 'L', 1); 
    $pdf->Cell(45, 6, $menueart, 1, 0, 'L', 1); 
    $pdf->Cell(45, 6, $datum, 1, 0, 'L', 1); 
    $pdf->Cell(30, 6, $wochentag, 1, 0, 'L', 1); 
    $pdf->Cell(40, 6, $vorspeise, 1, 0, 'L', 1); 
    $pdf->Cell(45, 6, $hauptspeise, 1, 0, 'L', 1); 
    $pdf->Cell(45, 6, $nachspeise, 1, 0, 'L', 1); 


    //Go to next row 
    $y_axis = $y_axis + $row_height; 
    $i = $i + 1; 
} 

mysqli_close($connect); 

//Create file 
$pdf->Output(); 
?> 

回答

0

我不知道,爲什麼會這樣,但你必須使用:

$pdf->SetXY(8, $y_axis_initial); 

或者您可以使用SetMargins設置頁邊距。

+0

btw:使用'utf8_decode($ text)'來顯示變音符號。 –

+0

我必須在哪裏放置該代碼? –

+0

而且你的代碼$ pdf-> SetXY(8,$ y_axis_initial);不會改變任何東西。仍然是同樣的問題 –