我创建了第一个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();
?>