FPDF 在不应该的地方添加页面 -PHP
FPDF adding a page where it's not suppose to -PHP
我有使用 FPDF 教程制作的代码
<?php
require('fpdf\fpdf.php');
class PDF extends FPDF
{
function Header()
{
//cabecera de la pagina
//lgo
$this->Image('simpca.png',10,10,25);
//fuente
$this->SetFont('Arial','B',15);
//Movemos a la derecha
$this->Cell(80);
//Titulo
$this->Cell(30,10,utf8_decode('Comprobante de impuesto sobre la renta'));
//Salto de linea
$this->Ln(20);
//fuente
$this->SetFont('Arial','B',10);
$this->Cell(0,10,utf8_decode('Carrera el saman, zona idustrial matanzas, puerto ordaz'),0,'L');
$this->Ln(04);
$this->Cell(0,10,utf8_decode('Telefonos: XXXXXXXXXXXXXXXXX'),0,'L');
$this->Ln(04);
$this->Cell(0,10,utf8_decode('Correo: XXXXXXXXXX'),0,'L');
$this->Ln(04);
$this->Cell(0,10,utf8_decode('Usuario: XXXXXXXXXXXXXXXXX'),0,'L');
$fecha=date("d-m-Y");
$this->Ln(04);
$this->Cell(0,10,utf8_decode('Fecha: ').$fecha,0,'L');
$this->Ln(06);
$this->Ln(06);
$this->Cell(0,10,utf8_decode('RETENCIONES DE ISLR'),0,0,'C');
}
function Basictable($pdf,$result)
{
$i=0;
//Datos
//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 = 25 || $i = 0)
{
//adds a page
$pdf->AddPage();
//set initial y axis position per page
$y_axis_initial = 70;
$y_axis = 69.9;
//print column titles for the current page
$pdf->SetFillColor(232,232,232);
$pdf->SetFont('Arial','B',10);
$pdf->SetY($y_axis_initial);
$pdf->SetX(30);
$pdf->Cell(25,6,'Documento',1,0,'L',1);
$pdf->Cell(30,6,'Numero',1,0,'L',1);
$pdf->Cell(20,6,'Codigo',1,0,'L',1);
$pdf->Cell(20,6,'Fecha',1,0,'L',1);
$pdf->Cell(20,6,'Monto',1,0,'L',1);
$pdf->Cell(20,6,'Objeto',1,0,'L',1);
$pdf->Cell(20,6,'Retenido',1,0,'L',1);
//Go to next row
$y_axis = $y_axis + $row_height;
//Set $i variable to 0 (first row)
$i = 0;
}
$emp_ccodigo = $row['emp_ccodigo'];
$pla_ccodigo = $row['pla_ccodigo'];
$prv_ccodigo = $row['prv_ccodigo'];
$doc_ccodigo = $row['doc_ccodigo'];
$mov_cnumero = $row['mov_cnumero'];
$ret_ccodigo = $row['ret_ccodigo'];
$isr_ffecha = $row['isr_ffecha'];
$time = strtotime($isr_ffecha);
$isr_ffecha1 = date('d-m-Y',$time);
$isr_nmonto = $row['isr_nmonto'];
$isr_nobjeto = $row['isr_nobjeto'];
$isr_nreteni = $row['isr_nreteni'];
$pdf->SetY($y_axis);
$pdf->SetX(30);
$pdf->SetFont('Arial','',8);
$pdf->Cell(25,6,$doc_ccodigo,1,0,'L',1);
$pdf->Cell(30,6,$mov_cnumero,1,0,'L',1);
$pdf->Cell(20,6,$ret_ccodigo,1,0,'R',1);
$pdf->Cell(20,6,$isr_ffecha1,1,0,'R',1);
$pdf->Cell(20,6,$isr_nmonto,1,0,'R',1);
$pdf->Cell(20,6,$isr_nobjeto,1,0,'R',1);
$pdf->Cell(20,6,$isr_nreteni,1,0,'R',1);
//Go to next row
$y_axis = $y_axis + $row_height;
$i = $i + 1;
}
}
function Footer()
{
//pos a 1,5cm del final
$this->SetY(-15);
//Arial Italic 8
$this->SetFont('Arial','I',8);
//numero depagina
$this->Cell(0,10,utf8_decode('Pagina ').$this->PageNo().' ',0,0,'C');
}
}
/////////////CONECTANDOSE A LA BD////////////////////////
$servername = "X";
$username = "X";
$password = "X";
// Creando la conexion
$conn = mysqli_connect($servername, $username, $password);
// Chequeando la conexion
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
//echo "Connected successfully \n";
//seleccionando la base de datos
mysqli_select_db($conn,"X")
or die("Could not select X");
$query="select * from islr where prv_ccodigo=106204";
$result=mysqli_query($conn,$query) or die('Error: '.mysql_error()."<BR>Query: '$query'");
//Create new pdf file
$pdf=new PDF();
//titulos de las columnas
$pdf->Basictable($pdf,$result);
//Send file
$pdf->Output();
mysql_close($conn);
?>
它添加一切正常,但它看起来像是在让 FPDF 添加一个新页面,所以在 $result 中我有超过 1 个项目,并且它添加了一个完整的页面(带有页眉和页脚) 对于我拥有的每一件物品。
是的,因为你的条件是作业。
if ($i = 25 || $i = 0)
应该是
if ($i == 25 || $i == 0)
我有使用 FPDF 教程制作的代码
<?php
require('fpdf\fpdf.php');
class PDF extends FPDF
{
function Header()
{
//cabecera de la pagina
//lgo
$this->Image('simpca.png',10,10,25);
//fuente
$this->SetFont('Arial','B',15);
//Movemos a la derecha
$this->Cell(80);
//Titulo
$this->Cell(30,10,utf8_decode('Comprobante de impuesto sobre la renta'));
//Salto de linea
$this->Ln(20);
//fuente
$this->SetFont('Arial','B',10);
$this->Cell(0,10,utf8_decode('Carrera el saman, zona idustrial matanzas, puerto ordaz'),0,'L');
$this->Ln(04);
$this->Cell(0,10,utf8_decode('Telefonos: XXXXXXXXXXXXXXXXX'),0,'L');
$this->Ln(04);
$this->Cell(0,10,utf8_decode('Correo: XXXXXXXXXX'),0,'L');
$this->Ln(04);
$this->Cell(0,10,utf8_decode('Usuario: XXXXXXXXXXXXXXXXX'),0,'L');
$fecha=date("d-m-Y");
$this->Ln(04);
$this->Cell(0,10,utf8_decode('Fecha: ').$fecha,0,'L');
$this->Ln(06);
$this->Ln(06);
$this->Cell(0,10,utf8_decode('RETENCIONES DE ISLR'),0,0,'C');
}
function Basictable($pdf,$result)
{
$i=0;
//Datos
//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 = 25 || $i = 0)
{
//adds a page
$pdf->AddPage();
//set initial y axis position per page
$y_axis_initial = 70;
$y_axis = 69.9;
//print column titles for the current page
$pdf->SetFillColor(232,232,232);
$pdf->SetFont('Arial','B',10);
$pdf->SetY($y_axis_initial);
$pdf->SetX(30);
$pdf->Cell(25,6,'Documento',1,0,'L',1);
$pdf->Cell(30,6,'Numero',1,0,'L',1);
$pdf->Cell(20,6,'Codigo',1,0,'L',1);
$pdf->Cell(20,6,'Fecha',1,0,'L',1);
$pdf->Cell(20,6,'Monto',1,0,'L',1);
$pdf->Cell(20,6,'Objeto',1,0,'L',1);
$pdf->Cell(20,6,'Retenido',1,0,'L',1);
//Go to next row
$y_axis = $y_axis + $row_height;
//Set $i variable to 0 (first row)
$i = 0;
}
$emp_ccodigo = $row['emp_ccodigo'];
$pla_ccodigo = $row['pla_ccodigo'];
$prv_ccodigo = $row['prv_ccodigo'];
$doc_ccodigo = $row['doc_ccodigo'];
$mov_cnumero = $row['mov_cnumero'];
$ret_ccodigo = $row['ret_ccodigo'];
$isr_ffecha = $row['isr_ffecha'];
$time = strtotime($isr_ffecha);
$isr_ffecha1 = date('d-m-Y',$time);
$isr_nmonto = $row['isr_nmonto'];
$isr_nobjeto = $row['isr_nobjeto'];
$isr_nreteni = $row['isr_nreteni'];
$pdf->SetY($y_axis);
$pdf->SetX(30);
$pdf->SetFont('Arial','',8);
$pdf->Cell(25,6,$doc_ccodigo,1,0,'L',1);
$pdf->Cell(30,6,$mov_cnumero,1,0,'L',1);
$pdf->Cell(20,6,$ret_ccodigo,1,0,'R',1);
$pdf->Cell(20,6,$isr_ffecha1,1,0,'R',1);
$pdf->Cell(20,6,$isr_nmonto,1,0,'R',1);
$pdf->Cell(20,6,$isr_nobjeto,1,0,'R',1);
$pdf->Cell(20,6,$isr_nreteni,1,0,'R',1);
//Go to next row
$y_axis = $y_axis + $row_height;
$i = $i + 1;
}
}
function Footer()
{
//pos a 1,5cm del final
$this->SetY(-15);
//Arial Italic 8
$this->SetFont('Arial','I',8);
//numero depagina
$this->Cell(0,10,utf8_decode('Pagina ').$this->PageNo().' ',0,0,'C');
}
}
/////////////CONECTANDOSE A LA BD////////////////////////
$servername = "X";
$username = "X";
$password = "X";
// Creando la conexion
$conn = mysqli_connect($servername, $username, $password);
// Chequeando la conexion
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
//echo "Connected successfully \n";
//seleccionando la base de datos
mysqli_select_db($conn,"X")
or die("Could not select X");
$query="select * from islr where prv_ccodigo=106204";
$result=mysqli_query($conn,$query) or die('Error: '.mysql_error()."<BR>Query: '$query'");
//Create new pdf file
$pdf=new PDF();
//titulos de las columnas
$pdf->Basictable($pdf,$result);
//Send file
$pdf->Output();
mysql_close($conn);
?>
它添加一切正常,但它看起来像是在让 FPDF 添加一个新页面,所以在 $result 中我有超过 1 个项目,并且它添加了一个完整的页面(带有页眉和页脚) 对于我拥有的每一件物品。
是的,因为你的条件是作业。
if ($i = 25 || $i = 0)
应该是
if ($i == 25 || $i == 0)