dswwuo1223 2015-08-31 17:55
浏览 53

FPDF - 改变$ pdf-> SetY的大小

I created my first fpdf page and inside my pdf I fetch data from my database. Everything is working so far, except the starting height of my file.

Please look at my file here: http://schulkantine.ccsolution.at/admin/speiseplan-pdf.php

As you can see it is too much on the top. I tried to change my current template but I am not able to change that issue.

Here is my code:

<?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();
?> 
  • 写回答

1条回答 默认 最新

  • douman6245 2015-08-31 18:25
    关注

    I don't know, why this is so, but you have to use:

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

    Alternatively you can use SetMargins to set page margins.

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭