PHP Code:
require_once('config/lang/eng.php');
require_once('tcpdf.php');
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Logo
//$image_file = K_PATH_IMAGES.'logo.jpg';
//$this->Image($image_file, 10, 10, 60, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
// Set font
$this->SetFont('helvetica', 'B', 25);
// Title
$this->Cell(0, 0, 'Trip Invoice', 0, false, 'R', 0, '', 0, false, 'T', 'M');
}
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'I', 8);
// Page number
//$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('MY Red Cap');
$pdf->SetTitle('My Trip Invoice');
$pdf->SetSubject('My Trip Invoice');
$pdf->SetKeywords(', PDF, Invoice, trip, guide');
// 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(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$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 some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set font
$pdf->SetFont('', '', 10);
// add a page
$pdf->AddPage();
echo $date=date("m/d/y");
require('htmlcolors.php');
// set some text to print
$html = <<<EOD
<table border="1" cellspacing="0" cellpadding="4" bottom="5">
<tr >
<td>$fullname<br />$address,$city <br /> $state<br />$zip<br />$phone</td><td align="right"> Invoice # $id<br />
DATE: $date</td>
</tr>
<tr>
<td width="35">TO</td><td width="604"></td>
</tr>
</table>
<br/>
<br/>
EOD;
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
// Print some HTML Cells
$pdf->SetFillColor(255,255,0);
// print a block of text using Write()
//$pdf->WriteHTML($html,$h=0,$txt, $link='', $fill=0, $align='L', $ln=true, $stretch=0, $firstline=false, $firstblock=false, $maxh=0);
// ---------------------------------------------------------
$filename=invoice_;
$file_name="$filename". rand().".pdf";
//Close and output PDF document
ob_clean();
$pdf->Output('tripinvoice/'.$file_name, 'D');
$pdf->Output('tripinvoice/'.$file_name, 'F');
// Exit script. So that no useless data is output-ed.
//============================================================+
// END OF FILE
//============================================================+
//-----------------------------END Code For PDF Generation--------------------\\
header("refresh: 3; URL=mytripinvoice.php?type=". $_GET['type']);
Bookmarks