这是我的Php代码,我使用的是fpdf
<?php
require('\lib\fpdf.php');
class PDF extends FPDF
{
//Page header
function Header()
{
//Logo
$this->Image('bis.png',10,20,33);
}
//Page footer
function Footer()
{
//Position at 1.5 cm from bottom
$this->SetY(-15);
//Arial italic 8
$this->SetFont('Arial','I',8);
//Page number
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
$pdf = new PDF();
$pdf->AddPage();
$pdf->AliasNbPages();
$pdf->SetAutoPageBreak(false);
// document properties
$pdf->SetAuthor('Karthik');
$pdf->SetTitle('PDF');
$pdf->SetXY(45,0);
$pdf->SetFont('Arial','B',14);
$pdf->Cell(100,50,'PROJECT X');
$pdf->SetXY(45,0);
$pdf->SetFont('Arial','B',10);
$pdf->Cell(0,60,"Office Address:");
$pdf->SetXY(45,0);
$pdf->SetFont('Courier','',10);
$pdf->Cell(0,70,"North Sydney");
$pdf->SetXY(45,0);
$pdf->SetFont('Arial','',10);
$pdf->Cell(0,80,"Ground Floor, 71 Walker Street");
$pdf->SetXY(45,0);
$pdf->SetFont('Arial','',10);
$pdf->Cell(0,90,"North Sydney NSW 2060.");
//Table Heading
$pdf->SetXY(10,0);
$pdf->SetFont('Arial','B',14);
$pdf->Cell(0,130,"Invoice");
// Add date report ran
$pdf->SetFont('Arial','I',10);
$date = date("F j, Y");
$pdf->SetXY(142,10);
$pdf->Cell(60,30,'Date: ' .$date);
$pdf->SetDrawColor(0, 0, 0); //black
//table header
$pdf->SetFillColor(170, 170, 170); //gray
$pdf->setFont("Arial","B","9");
$pdf->setXY(10, 70);
$pdf->Cell(10, 10, "id", 1, 0, "L", 1); // CHANGE THESE TO REPRESENT YOUR
FIELDS
$pdf->Cell(30, 10, "Date", 1, 0, "L", 1);
// $pdf -> SetY(5);
$pdf->Cell(60, 10, "Name", 1, 0, "L", 1);
$pdf->Cell(30, 10, "Item", 1, 0, "L", 1);
$pdf->Cell(20, 10, "GST", 1, 0, "L", 1);
$pdf->Cell(25, 10, "Price", 1, 0, "L", 1);
//Data Access From The Database
$x = 10;
$y = 80;
$pdf->setXY($x, $y);
$pdf->setFont("Arial","","9");
include('api/db_config.php');
$query_result = "SELECT * FROM projectx";
$result = mysql_query($query_result, $conOpen) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$pdf->Cell(10, 8, $row['id'], 1); // CHANGE THESE TO REPRESENT YOUR
FIELDS
$pdf->Cell(30, 8, $row['date'], 1);
$pdf->MultiCell(60, 8, $row['Name'], 1);
$pdf->Cell(30, 8, $row['Item'], 1);
$pdf->Cell(20, 8, $row['GST'], 1);
$pdf->Cell(25, 8, $row['Price'], 1);
// header('Content-Type: application/pdf');
// header('Content-Disposition: attachment; filename=download.pdf');
$y += 8;
if ($y > 260) // When you need a page break
{
$pdf->AddPage();
$y = 40;
}
$pdf->setXY($x, $y);
}
$pdf->SetXY(150,100);
$pdf->SetFont('Arial','B',10);
$pdf->Cell(0,90,"TOTAL");
$pdf->SetXY(165,100);
$pdf->SetFont('Arial','',10);
$pdf->Cell(0,90,"$ 88");
$pdf->Output();
这是我的PDF图像
这里我使用fpdf生成pdf文件,我有5列,如果名称列包含更多字符,那么句子不适合应该在下一行中打印的行,因为我在使用后使用MultiCell如图所示,其他列也会向下一步。提前谢谢。