【问题标题】:How to improve rendering in FPDF? [closed]如何改进 FPDF 中的渲染? [关闭]
【发布时间】:2013-05-18 14:27:44
【问题描述】:
<?php

$factuurnr = $_GET['factuurnr'];



require('fpdf/fpdf.php');

//Connect to your database
include("db_connect.php");

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

//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(232, 232, 232);
$pdf->SetFont('Arial', 'B', 12);
$pdf->SetY($y_axis_initial);
$pdf->SetX(25);
$pdf->Cell(30, 6, 'klantnummer', 1, 0, 'L', 1);
$pdf->Cell(100, 6, 'factuurnummer', 1, 0, 'L', 1);
$pdf->Cell(30, 6, 'bedrag', 1, 0, 'R', 1);

$y_axis = $y_axis + $row_height;

//Select the Products you want to show in your PDF file
 $query="SELECT * FROM facturen WHERE factuurnummer = '$factuurnr'";
 $result=mysql_query($query);



 //initialize counter
 $i = 0;

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

//Set Row Height
$row_height = 6;

while($row = mysql_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, 'klantnummer', 1, 0, 'L', 1);
    $pdf->Cell(100, 6, 'factuurnummer', 1, 0, 'L', 1);
    $pdf->Cell(30, 6, 'bedrag', 1, 0, 'R', 1);

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

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

$klantnummer = $row['klantnummer'];
$factuurnummer = $row['factuurnummer'];
$bedrag = $row['bedrag'];

$pdf->SetY($y_axis);
$pdf->SetX(25);

$pdf->Cell(30, 6, $klantnummer, 1, 0, 'L', 1);
$pdf->Cell(100, 6, $factuurnummer, 1, 0, 'L', 1);
$pdf->Cell(30, 6, $bedrag, 1, 0, 'R', 1);

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

mysql_close;

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

我正在尝试使用 fpdf 生成包含来自 MySQL 的信息的 pdf。老实说,它正在工作,但是渲染已关闭,而且我对 fpdf 太陌生,无法弄清楚这一点。

来自 MySQL 的数据在表头上方呈现,我不知道为什么。

【问题讨论】:

标签: php mysql fpdf


【解决方案1】:

可能您的初始 $y_axis 设置是错误的。 试试这个:

$y_axis = $y_axis_initial + $row_height;

我认为您应该替换 3 条“$y_axis = ...”行中的 2 条(最后一条可以)。

【讨论】:

  • Thnx 伙计,这确实是问题所在。
猜你喜欢
  • 2018-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-20
  • 1970-01-01
  • 2015-02-27
相关资源
最近更新 更多