我正在使用TCPDF生成pdf报告。但我有一个有线问题,在第一页标题从正确/正确的y位置开始,但从第2页开始它向下... ...
这是我正在使用的代码:
<?php
require_once('./../../../Classes/tcpdf/config/tcpdf_config.php');
require_once('./../../../Classes/tcpdf/tcpdf.php');
class MYPDF extends TCPDF
{
//Page header
public function Header()
{
// Logo
$this->Image('./../../../images/bdGovt-Logo.gif', 5, 8, 25, '', 'GIF', '', 'T', false, 300, '', false, false, 0, false, false, false);
$this->Image('./../../../images/SEQAEP-Logo.gif', 275, 8, 15, '', 'GIF', '', 'T', false, 300, '', false, false, 0, false, false, false);
// Set font
$this->SetFont('helvetica', 'B', 12);
// Title
$this->ln();
$this->Cell(0, 0, 'Government Of People\'s Republic Of Bangladesh', 0, false, 'C', 0, '', 0, false, 'M', 'M');
$this->ln();
$this->Cell(0, 0, 'Secondary Education Quality & Access Enhancement Project (SEQAEP)', 0, false, 'C', 0, '', 0, false, 'M', 'M');
$this->ln();
$this->Cell(0, 0, 'Award Confirmation Form For Stipend And Tution', 0, false, 'C', 0, '', 0, false, 'M', 'M');
$this->ln();
$this->SetFont('', 'B', 10);
$this->Cell(0, 0, 'Semester: Jan - Jun 2015', 0, false, 'C', 0, '', 0, false, 'M', 'M');
$this->ln();
}
// Page footer
public function Footer()
{
// Position at 15 mm from bottom
$this->SetY(-20);
// Set font
$this->SetFont('helvetica', '', 8);
$this->MultiCell(93, 0, str_repeat('_', 45) . "\r\n" . 'Signature of Head of the Institute' . "\r\n" . 'Include Name with Official Seal', 0, 'C', 0, 0);
$this->MultiCell(94, 0, str_repeat('_', 45) . "\r\n" . 'Signature of Upazila Secondary Education Officer' . "\r\n" . 'Include Name with Official Seal', 0, 'C', 0, 0);
$this->MultiCell(93, 0, str_repeat('_', 45) . "\r\n" . 'Signature of Bank Officer' . "\r\n" . 'Include Name with Official Seal', 0, 'C', 0, 0);
$this->ln();
// Page number
$this->Cell(0, 10, 'Page ' . $this->getAliasNumPage() .' of ' . $this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');
}
}
$pdf = new MYPDF('P', PDF_UNIT, 'A3', true, 'UTF-8', false);
// set document information
$pdf->SetCreator('Mobile: +8801717219006');
$pdf->SetAuthor('Mohammad Kamrul Hassan');
$pdf->SetTitle('Siam Computer');
$pdf->SetSubject('Email: support@siamcomputer-bd.com');
$pdf->SetKeywords('www.siamcomputer-bd.com');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(10, 27, 10);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set font
$pdf->SetFont('helvetica', 'B', 10);
// set cell padding
$pdf->setCellPaddings(1.000125, 1.000125, 1.000125, 1.000125);
// add a page
$pdf->AddPage();
$pdf->SetFont('helvetica', '', 8);
$strSInfoName = array('Location Code:', 'Bank Branch Code:', 'Bank Branch Name:', 'Division Name:', 'District Name:', 'Upazila Name:', 'Institute ID:', 'Institute Name:', 'EIIN No:');
$strSInfoValue = array('20902', '05229', 'GUNAGARI', 'CHITTAGONG', 'CHITTAGONG', 'BANSHKHALI', '01000400', 'MONAYEM SHAH AULIA HIGH SCHOOL', '104054');
$pdf->ln();
//file_put_contents('./wtf.txt', $pdf->GetY());
foreach($strSInfoName as $key => $value)
{
$pdf->Cell(30, 5, $strSInfoName[$key], 0, 0, 'L', 0);
$pdf->Cell(75, 5, $strSInfoValue[$key], 0, 0, 'L', 0);
$pdf->ln();
}
$pdf->SetFont('helvetica', 'B', 8);
$pdf->SetY(27);
$pdf->SetX(165);
$pdf->Cell(125, 0, 'Institution Summary', 1, 0, 'C', 0);
$pdf->ln();
$pdf->SetX(165);
$pdf->Cell(15, 11, 'Class', 1, 0, 'C', 0);
$pdf->Cell(20, 11, 'Students', 1, 0, 'C', 0);
$pdf->Cell(90, 0, 'Bellow Figures Showed In Taka', 1, 0, 'C', 0);
$pdf->ln();
$pdf->SetX(165);
$pdf->Cell(35, 0, '', 0, 0, 'C', 0);
$pdf->Cell(20, 0, 'Stipend', 1, 0, 'C', 0);
$pdf->Cell(20, 0, 'Tution', 1, 0, 'C', 0);
$pdf->Cell(30, 0, 'SSC Exam Fees', 1, 0, 'C', 0);
$pdf->Cell(20, 0, 'Total', 1, 0, 'C', 0);
$pdf->ln();
$pdf->SetFont('helvetica', '', 8);
$strDummyArray = array_fill(0, 6, '00');
$strDummyArray = array_fill(0, 6, $strDummyArray);
$strSizeArray = array(15, 20, 20, 20, 30, 20);
foreach($strDummyArray as $row)
{
$pdf->SetX(165);
foreach($row as $key=>$col)
{
$pdf->Cell($strSizeArray[$key], 0, $col, 1, 0, 'C', 0);
}
$pdf->ln();
}
$pdf->ln();
$pdf->ln();
$pdf->SetFont('helvetica', 'B', 8);
$pdf->Cell(10, 0, 'Class:', 0, 0, 'L', 0);
$pdf->SetFont('helvetica', '', 8);
$pdf->Cell(10, 0, '6', 0, 0, 'L', 0);
$pdf->ln();
$pdf->ln();
$pdf->Cell(7.5, 0, 'SL', 1, 0, 'C', 0);
$pdf->Cell(60, 0, 'Student Information', 1, 0, 'C', 0);
$pdf->Cell(15, 0, 'Stipened', 1, 0, 'C', 0);
$pdf->Cell(20, 0, 'Photo', 1, 0, 'C', 0);
$pdf->Cell(37.5, 0, 'Signature', 1, 0, 'C', 0);
$pdf->Cell(7.5, 0, 'SL', 1, 0, 'C', 0);
$pdf->Cell(60, 0, 'Student Information', 1, 0, 'C', 0);
$pdf->Cell(15, 0, 'Stipened', 1, 0, 'C', 0);
$pdf->Cell(20, 0, 'Photo', 1, 0, 'C', 0);
$pdf->Cell(37.5, 0, 'Signature', 1, 0, 'C', 0);
$pdf->ln();
$pdf->AddPage();
//Close and output PDF document
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="test.pdf"', false);
$pdf->Output('test-' . time() . '.pdf', 'I');
?>
这就是生成的pdf(截图)的样子:
我希望它从每页的相同位置开始作为第一页
希望有道理吗? :)