Php FPDF-更改$pdf的大小->;塞蒂

Php FPDF-更改$pdf的大小->;塞蒂,php,pdf,fpdf,Php,Pdf,Fpdf,我创建了我的第一个fpdf页面,并在pdf中从数据库中获取数据。到目前为止,除了我的文件的起始高度,一切都正常 请看我的档案: 正如你所看到的,它在顶部太多了。我试图更改当前模板,但无法更改该问题 这是我的密码: <?php require('../assets/fpdf17/fpdf.php'); //Connect to your database // Create connection credentials $db_host = 'localhost'; $db_name =

我创建了我的第一个
fpdf
页面,并在
pdf
中从数据库中获取数据。到目前为止,除了我的文件的起始高度,一切都正常

请看我的档案:

正如你所看到的,它在顶部太多了。我试图更改当前模板,但无法更改该问题

这是我的密码:

<?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();
?> 

我不知道为什么会这样,但您必须使用:

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

或者,您可以使用设置页边距。

我不知道为什么会这样,但您必须使用:

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

或者,您可以使用设置页边距。

以及您的代码$pdf->SetXY(8,$y\u axis\u initial);不会改变任何事情。仍然存在相同的问题替换
$pdf->SetY($y\u axis\u initial)$pdf->SetX(8)与我的代码。这应该是可行的…还有你的代码$pdf->SetXY(8,$y\u axis\u initial);不会改变任何事情。仍然存在相同的问题替换
$pdf->SetY($y\u axis\u initial)$pdf->SetX(8)与我的代码。那应该有用。。。