Good Day Guys! I need some help when using TCPDF, I have this problem where the first page renders the details ok but on the second page, all the details are stacked at one area, I'm using MultiCell for the details.
public function PageHeader() {
$this->SetMargins(5, $this->GetY(), -1, true);
$this->SetCellPadding(0);
}
private function _addPage() {
$top_margin = 50;
$this->AddPage();
$this->setCellHeightRatio(1.25);
$this->SetMargins(5, $top_margin, 5, true);
$this->SetTopMargin($top_margin);
}
Related
I need to remove a watermark on the last page of my PDF, but I can't detect the last page in the header Yes I can do it in the footer.
protected $last_page_flag = false;
public function Close() {
$this->last_page_flag = true;
parent::Close();
}
public function Footer(){
if ($this->last_page_flag ){
//this work fine
}
}
//But I can't detect the last page in the header, which is where I put the watermark.
public function Header(){
$img_file = K_PATH_IMAGES.'marca_agua.jpg';
$this->Image($img_file, 12, 80, 185, 180, '', '', '', false, 300, '', false, false, 0);
$this->setPageMark();
//if I do
if ($this->last_page_flag ){
//Do nothing...
}
}
My pdf has a dynamic number of pages and I need to remove the watermark on the last one. How can I detect if it is the last page in the header?
Or how can I insert the watermark in a section other than the header?
Thanks! I am really desperate with this problem because it is the last thing I have left to deliver a job and I have been trying it for two days without a solution.
You have to update the value of $tcpdflink to false in /tcpdf/tcpdf.php
/**
* If true print TCPDF meta link.
* #protected
* #since 5.9.152 (2012-03-23)
*/
protected $tcpdflink = false;
Also (or instead), update the value on the constructor:
$this->tcpdflink = false;
First time use TCPDF, great library.
I try to create a custom footer, however i want to create a custom footer that include the page number and date inside a div with top and bottom border! So any help?
Many Thanks
Karel is right on this.
you could however ignore the Footer() function if it's getting you in trouble with the dynamic of it. seems to me that you would like to have a div in your footer.
to do this you have to get rid of the default footer first:
$this->setPrintFooter(false);
and then create your own footer function.
public function _footer($input) {
$html = $input;
$this->setY(-15); // so the footer is an actual footer.
$this->writeHTMLCell(
$width = 0, // width of the cell, not the input
$height = 0, // height of the cell..
$x,
$y,
$html = '', // your input.
$border = 0,
$ln = 0,
$fill = false,
$reseth = true,
$align = '',
$autopadding = true
);
}
the values of the above function are the defaults. so you may want to edit them.
with a call like this:
$div = '<div id="footer">wow this is a nice footer</div>'>
$pdf->_footer($div);
you create your HTML cell with the $div input.
to get the page numbers and stuff like that just checkout the TCPDF documentation page: http://www.tcpdf.org/doc/code/classTCPDF.html
hope this helps a little bit to understand it.
this is just an example from scratch.
edit it as you like and try out some stuff to get your PDF document going.
You can extend the TCPDF class and add your custom Footer function. Here's an example that I've used, see if it fits and modify to your own needs. It doesn't use a <div> to render the footer, that wasn't possible at the time I wrote this (might be now though, TCPDF is evolving rapidly).
class MyPDF extends TCPDF {
public function Footer() {
$this->SetY(-15);
$this->SetFont('helvetica', 'I', 8);
$this->Cell(0, 10,
'Page ' . $this->getAliasNumPage() . ' of total ' .
$this->getAliasNbPages(), 0, false, 'C', 0, '',
0, false, 'T', 'M');
}
public function Header() {
// add custom header stuff here
}
}
$pdf = new MyPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT,
true, 'UTF-8', false);
I am using TCPDF to generate PDF documents. The problem I have is that I am trying to add a different footer per page. Apparently, TCPDF provides a solution only for a single footer.
Each footer contains only basic html code without any styling.
Any ideas?
You can turn of the default footer like this:
$pdf->SetPrintFooter(false);
create your own one like this:
$footer = 'yau man footer stuff';
and then create your own footer function:
public function _footer($input) {
$text = $input;
$pdf->setY(-15); // or whatever location your footer should be displayed.
$pdf->Cell ( // or another method like Write(), WriteHTML() ..
$width = 0, // width of the cell, not the input
$height = 0, // height of the cell..
$x,
$y,
$text = '', // your input.
$border = 0,
$ln = 0,
$fill = false,
$reseth = true,
$align = '',
$autopadding = true
);
}
by calling $pdf->_footer($footer); you create your own footer
You can create custom Header and Footer by exporting TCPDF in class and you use that class anywhere!
class MYPDF extends TCPDF {
//Page header
public function Header() {
//Header code
}
// Page footer
public function Footer() {
//Footer code
//you have $this->PageNo() where you can add conditional UI
}
}
And you can use this class as
$o_pdf = new MyPDF([all params TCPDF requires]);
I hope this will help you! Happy coading!!!
I want to create second page using fpdf.The code is given below.In the code from the specified area i want to start new page.Here the pdf class is extends from fpdf.
class PDF extends FPDF
{
function header{
$this->Ln(20);
$this->SetFont('Times','',10);
$this->Cell(0,10,'Kondotty');
$this->Ln(10);
$this->SetFont('Times','',10);
$this->Cell(80,0,'07/10/2014');
$this->Cell(60,0,'Seal');
$this->Cell(0,0,'Head of Institution');
//END FIRST PAGE
// STARTING SECOND PAGE
$this->Ln(10);
$this->Cell(27);
$this->Cell(0,10,'Her conduct and character were found ...................................... during that period.');
$this->Ln(20);
$this->SetFont('Times','',10);
$this->Cell(0,10,'Kondotty');
$this->Ln(10);
$this->SetFont('Times','',10);
$this->Cell(80,0,'07/10/2014');
}
}
For example:
I declare $i = 0; at the beginning of my PDF and for every line I add in my foreach I count $i like $i++.
If you want a pagebreak after x lines for example you can just say:
if($i%30==0 && $i!=0) {
$this->addPage();
}
And a function to add a new page:
private function addPage()
{
$this->page = $this->pdf->newPage('A4');
I hope this will point you in the right direction.
I'm trying to generate a pdf using the FPDF class but the problem I'm having is how to pass variable data fetched from mysql database (queried data are stored in an array) into the pdf generated.
Here are the codes in the script meant to generate the pdf
<?php
#include_once("includes/db.php");
require('fpdf/fpdf.php');
#include_once("includes/course_info_query.php");
$obj = new trainingCourses();
$course_details = array();
if(isset($_GET['c_id'])){
$course_details = $obj->getPubCourseDetails($_GET['c_id']);
}
class PDF extends FPDF
{
public $course_details;
public function setData($input){
$this->course_details = $input;
}
function Header()
{
// Logo
$this->Image('s_pdf_logo.png',10,6,30);
// Arial bold 15
$this->SetFont('Arial','B',20);
// Move to the right
$this->Cell(40);
// Title
$this->Cell(30,10,$this->course_details['comp_name']);
// Draw an header line
$this->Line(10,26,200,26);
// Line break
$this->Ln(20);
}
function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-15);
// Begin with regular font
$this->SetFont('Arial','',9);
// Then put a blue underlined link
//$this->SetTextColor(0,0,255);
$this->SetFont('','U');
$this->Write(10,$this->course_details['comp_name'],'http://www.skills.com');
// Arial italic 8
$this->SetFont('Arial','I',9);
// Page number
$this->Cell(0,10,'Page '.$this->PageNo().' ',0,0,'R');
}
function BodyTop()
{
// Course title cell
$this->Cell('',10,'',0,0,'C');
$this->Ln();
/* Build cells for the first row */
$this->SetFont('Arial','',10);
$this->SetY(40);
// First Row
$this->Cell(35,8,'Starting Date : ',0,0,'L');
$this->Cell(30,8,$this->course_details['event_date'],0,0,'C');
$this->SetX(150);
$this->Cell(25,8,'Course Fee : ',0,0,'L');
$this->Cell(20,8,$this->course_details['fee'],0,0,'C');
$this->Ln();
// Second Row
$this->Cell(35,8,'Seating Capacity : ',0,0,'L');
$this->Cell(30,8,$this->course_details['sit_capacity'],0,0,'L');
$this->SetX(150);
$this->Cell(25,8,'Duration : ',0,0,'L');
$this->Cell(20,8,$this->course_details['duration'].' Day(s)',0,0,'L');
$this->Ln();
// Third Row
$this->Cell(35,8,'Venue : ',0,0,'L');
$this->Cell(30,8,$this->course_details['venue'],0,0,'L');
$this->SetX(150);
$this->Cell(25,8,'City : ',0,0,'L');
$this->Cell(20,8,$this->course_details['city'],0,0,'L');
$this->Ln();
// Fourth Row
$this->Cell(35,8,'Other Details : ',0,0,'L');
$this->Cell(150,8,$this->course_details['other_det'],0,0,'L');
$this->Ln();
}
function CourseBody()
{
$this->SetY(80);
//$this->WriteHTML($html);
$this->Write(10,$this->course_details['desc']);
}
function PrintChapter()
{
$this->AddPage();
$this->BodyTop();
$this->CourseBody();
}
}
$pdf = new PDF();
$pdf->setData($course_details);
//$pdf->Header();
$pdf->SetAuthor($this->course_details['comp_name']);
$pdf->PrintChapter();
$pdf->Output();
?>
I hope to get some help with this...Thanks
It's just basic OOP (object oriented programming) really.
Add a variable to your PDF Class as such:
public $data;
Add a function within your PDF Class which accepts a parameter and use this function to set the variable above:
public function setData($input){
$this->data = $input;
}
And then you'll be able to access $this->data from within your PDF Class. Don't forget to actually call the function that you just defined (just after the constructor).
EDIT:
To set the data:
$pdf = new PDF();
$pdf->setData($course_details);
Then within your PDF class $this->data will be your array. You might want to do the following so you can understand the format of your array:
print_r($this->data);