<?php // demo/temp_adp_toronto.php
/**
* http://www.experts-exchange.com/questions/28693143/Configuring-TCPDF-with-Header-and-Footer.html#a40857620
*
* Demonstrate how to put an image into a TCPDF document
* and write some text over part of the image
*
* See http://www.tcpdf.org/doc/code/annotated.html
*/
error_reporting(E_ALL);
// A DATE SETTING MAY BE REQUIRED - DEPENDS ON PHP INSTALLATION SETTINGS
date_default_timezone_set('America/Chicago');
// SYNTHESIZE THE PDF FILE URL AND FILE NAME
$pdf_file_link = 'storage/tcpdf_example.pdf';
$pdf_file_name = getcwd() . DIRECTORY_SEPARATOR . $pdf_file_link;
// LOAD THE TCPDF CLASS AND CONFIGURATION
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
// EXTEND THE TCPDF OBJECT SO WE CAN SUBSTITUTE OUR OWN METHODS
class PDF extends TCPDF
{
// NULLIFY AUTOMATIC FOOTER
public function Footer() {}
// ADD CUSTOM HEADER
public function Header()
{
$this->SetFont('helvetica', 'B', 20);
$this->Cell
( 0 // $w width
, 15 // $h height
, $this->headerText
, 0 // border
, 1 // move cursor to next line after
, 'L' // left-align text
, FALSE // no fill
, '' // link (none)
, 0 // stretch disabled
, FALSE // ignore min height
, 'T' // cell align
, 'C' // text aligh
)
;
}
}
// INSTANTIATE THE OBJECT
$pdf = new PDF('P', 'mm', 'LETTER', true, 'UTF-8', false);
// SET THE TEXT FOR THIS HEADER
$pdf->headerText = 'Anything you want ' . date('c');
// ADD A PAGE
$pdf->AddPage('P', 'LETTER', TRUE);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetAutoPageBreak(FALSE);
$pdf->setLanguageArray($l);
$pdf->SetFont('times', '', 13);
$pdf->setCellPaddings(0,0,0,0);
$pdf->setCellMargins(0,0,0,0);
// NO CELL BORDER IS NEEDED
$bdr = 0;
// ADD AN IMAGE
$img = 'images/ray_padded.png';
// I HAVE NO IDEA WHAT THIS IS DOING TO IMAGE SCALE - EXPERIMENT WITH IT
$pdf->setImageScale(1.53);
// GET THE IMAGE SETTINGS
$pdf->Image
( $img
, 0 // $x
, 30 // $y
, 0 // WIDTH
, 0 // HEIGHT
, 'PNG' // TYPE
, '#' // LINK URL
, 'T' // SET POINTER TOP LEFT
, FALSE // NO RESIZING
, 300 // DPI
, 'L' // PALIGN
, FALSE // ISMASK
, FALSE // IMGMASK
, 0 // BORDER
, FALSE // FIT TO BOX
, FALSE // HIDDEN
, FALSE // FIT ON PAGE
)
;
// ADD SOME TEXT ON TOP OF THE IMAGE
$pdf->Text
( 24 // $x,
, 30+24 // $y,
, 'This is Ray'
, FALSE // $fstroke = false,
, FALSE // $fclip = false,
, TRUE // $ffill = true,
, $bdr // $border = whatever,
, 2 // $ln = 0, 2=PUT CURSOR BELOW
, '' // $align = '', DEFAULT LEFT
, FALSE // $fill = false, CELL BACKGROUND
, '' // $link = '', NOT A LINK
, 0 // $stretch = 0, NO TEXT STRETCH
, FALSE // $ignore_min_height = false,
, 'A' // $calign = 'T', A=FONT TOP INSIDE CELL
, 'T' // $valign = 'M', T=VERTICAL ALIGN INSIDE CELL
, TRUE // $rtloff = false TRUE = USE PAGE TOP LEFT CORNER TO ALIGN
)
;
// CHANGE THE TEXT FOR THIS HEADER
$pdf->headerText = 'New headerText';
// ADD ANOTHER PAGE
$pdf->AddPage('P', 'LETTER', TRUE);
// ADD SOME TEXT ON THIS PAGE
$my_text = 'This is the second page';
$pdf->Text
( 24 // $x,
, 30+24 // $y,
, $my_text
, FALSE // $fstroke = false,
, FALSE // $fclip = false,
, TRUE // $ffill = true,
, $bdr // $border = whatever,
, 2 // $ln = 0, 2=PUT CURSOR BELOW
, '' // $align = '', DEFAULT LEFT
, FALSE // $fill = false, CELL BACKGROUND
, '' // $link = '', NOT A LINK
, 0 // $stretch = 0, NO TEXT STRETCH
, FALSE // $ignore_min_height = false,
, 'A' // $calign = 'T', A=FONT TOP INSIDE CELL
, 'T' // $valign = 'M', T=VERTICAL ALIGN INSIDE CELL
, TRUE // $rtloff = false TRUE = USE PAGE TOP LEFT CORNER TO ALIGN
)
;
// WRITE THE PDF FILE TO THE SERVER
$pdf->Output($pdf_file_name, 'F');
// PRESENT A CLICKABLE LINK SO WE CAN D/L AND PRINT THE PDF
echo '<a target="my_PDF" href="' . $pdf_file_link . '"><strong>Print the PDF</strong></a>';
<?php
// SYNTHESIZE THE PDF FILE URL AND FILE NAME
$pdf_file_name = 'test.pdf';
// LOAD THE TCPDF CLASS AND CONFIGURATION
$currentDIR = getcwd();
chdir("../");
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
//Change DIR back
chdir($currentDIR);
<?php
//Temporarily Change directory to TCPDF to load files...
$currentDIR = getcwd();
chdir("../tcpdf/examples");
require_once('tcpdf_include.php');
//Change DIR back
chdir($currentDIR);
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Title
$this->Ln();
$page = $this->getAliasNumPage();
if ($page == 1){
$this->Cell(0, 15, 'Page 1', 0, false, 'C', 0, '', 0, false, 'M', 'M');
$this->Ln();
}
$this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', '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');
}
}
$pdf = new MYPDF('L', 'mm', array(215.9, 279.4));
$pdf->SetTitle('Manifest');
$pdf->SetMargins(5, 5);
$pdf->SetAutoPageBreak(TRUE);
$pdf->SetPrintHeader(TRUE);
$pdf->SetHeaderMargin(10);
$pdf->SetFont('Helvetica', '', 9);
$pdf->AddPage();
$pdf->AddPage();
$pdf->AddPage();
$file = 'Manifest.pdf';
$pdf->Output($file);
?>