Using fpdf to create my document, it works perfectly but for one thing. There is a superposition a one line on the footer part.
Here is my Pdf class header function :
function Header() {
$this->setY(40);
$titre="MY TITLE";
$this->SetFont('Arial','B',16);
.....
doing all my stuff
.....
$this->Ln();
}
Here is the Footer method :
function Footer() {
$this->SetY(-25); --postionning footer at 2.5 cm from the bottom
....
doing my stuff
}
calling program:
$pdf = new Pdf();
$pdf->Open();
$pdf->addPage();
$request= "SELECT.....";
$result = $link->query($request) ;
while($row=$result->fetchRow()) {
$pdf->SetX(18);
foreach($row as $champ=>$valeur) {
....
displaying the fields in the document
...
}
$pdf->Ln();
}
My problem : it displays 1 line too much that superposes the Footer.
I would like to give a position between the footer and the inner page. Is that possible?
Thank you
Use the SetAutoPageBreak() method to increase the bottom margin, for example:
$pdf = new Pdf();
$pdf->SetAutoPageBreak(true, 40);
I Have form in that i am displaying data.When I click on the print button I am going to save the data in pdf format for printing for that I am using FPDF Library.The problem is when i send the data from the controller to view only headers displaying like below But Data is not displaying. I have written my view file like below.I have got stuck since yesterday.I Have getting the data in controller but not passing to the view.I can't understand why it is happening .The Way i am doing wrong or what please any help Would be Appreciated.Thanks in Advance.
My controller Code
public function printpage(){
$this->load->library('Myfpdf');
$data['result']=$this->Vendor_Model->displaydata();
if(!empty(array_filter($data))){
$this->load->view('Savedata',$data);
}else{
redirect('Vendorcontroller/showeditview');
}
}
My Modal code for getting the data from the database
public function displaydata(){
$query=$this->db->query('SELECT `vndr_id`, s.state as state,`vndr_name`, `vndr_address`, `vndr_pincode`, `vndr_telephone`, `vndr_mobile`, `vndr_mailid`, `vndr_country`, `vndr_gsttin`, `vndr_cstno`, `vndr_totaldebit`, `vndr_totalcredit`, `vndr_bankname`, `vndr_acno`, `vndr_ifsccode` FROM `vendors` vndr INNER JOIN states s ON vndr_state=s.state_id order by vndr_id');
if($query->num_rows()>0){
return $query->result_array();
}
}
My view code for print the data as pdf format
class printview extends FPDF
{
function Header()
{
$this->SetFont('Arial','B',15);
$this->Cell(276,5,"VendorDetails",0,0,'C');
$this->ln(15);
$this->SetFont('Arial','B',10);
$this->Cell(55,10,"Name",1,0,'C');
$this->Cell(90,10,"Address",1,0,'C');
$this->Cell(50,10,"Telephone",1,0,'C');
$this->Cell(70,10,"Email",1,0,'C');
$this->ln();
}
function Footer(){
$this->SetY(-15);
$this->SetFont('Arial','I',8);
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
function viewdata(){
if(isset($result)){
foreach($result as $values){
$this->SetFont('Arial','',10);
$this->Cell(55,10,$values['vndr_name'],1,0,'L');
$this->Cell(90,10,$values['vndr_address'].','.$values['state'].'-'.$values['vndr_pincode'],1,0,'L');
$this->Cell(50,10,$values['vndr_telephone'].','.$values['vndr_mobile'],1,0,'L');
$this->Cell(70,10,$values['vndr_mailid'],1,0,'L');
$this->ln();
}
}
}
}
$this->pdf = new Printview();
$this->pdf->SetMargins(15, 10, 20);
$this->pdf->AliasNbPages();
$this->pdf->AddPage('L','A4',0);
$this->pdf->viewdata();
$this->pdf->Output();
This is Fdf library class
require('fpdf/fpdf.php');
class Myfpdf extends fpdf
{
function __construct(){
parent::__construct();
$ci=& get_instance();
}
}
Try to pass the $result data as a parameter :
$this->pdf->viewdata($result);
And also on the method :
function viewdata($result){
...
}
I Have changed this way it is working fine now.
This is controller
-------------------------
public function printpage(){
$this->load->library('Myfpdf');
$data['result']=$this->Vendor_Model->displaydata();
if(!empty(array_filter($data))){
$this->load->view('Savedata',$data);
}else{
redirect('Vendorcontroller/showeditview');
}
}
This is view file
function viewdata($result){
if(isset($result)){
foreach($result as $values){
$this->SetFont('Arial','',10);
$this->Cell(55,10,$values['vndr_name'],1,0,'L');
$this->Cell(90,10,$values['vndr_address'].','.$values['state'].'-'.$values['vndr_pincode'],1,0,'L');
$this->Cell(50,10,$values['vndr_telephone'].','.$values['vndr_mobile'],1,0,'L');
$this->Cell(70,10,$values['vndr_mailid'],1,0,'L');
$this->ln();
}
}
}
}
$this->pdf = new Printview();
$this->pdf->SetMargins(15, 10, 20);
$this->pdf->AliasNbPages();
$this->pdf->AddPage('L','A4',0);
$this->pdf->viewdata($result);
$this->pdf->Output();
I want to divide page in to two column using FPDF. I am using below code which created pdf in two cloumn but issue is that the gap is some bit more between column. I want to reduce gap between the column only.
My code here
class PDF extends FPDF
{
protected $col = 0; // Current column
protected $y0; // Ordinate of column start
function Header()
{
}
function Footer()
{
}
function SetCol($col)
{
// Set position at a given column
$this->col = $col;
$x = 10+$col*50;
$this->SetLeftMargin($x);
$this->SetX($x);
}
function AcceptPageBreak()
{
if($this->col<2)
{
// Go to next column
$this->SetCol($this->col+2);
// Set ordinate to top
$this->SetY($this->y0);
// Keep on page
return false;
}
else
{
// Go back to first column
$this->SetCol(0);
// Page break
return true;
}
}
function ChapterBody($file)
{
$txt = file_get_contents($file);
$this->SetFont('Times','',12);
$this->MultiCell(100, 7, $txt);
$this->Ln();
$this->SetCol(0);
}
function PrintChapter($num, $title, $file)
{
// Add chapter
$this->AddPage();
$this->ChapterBody($file);
}
}
$pdf = new PDF();
$title = '20000 Leagues Under the Seas';
$pdf->SetTitle($title);
$pdf->SetAuthor('Jules Verne');
$pdf->PrintChapter(1,'A RUNAWAY REEF','20k_c1.txt');
$pdf->Output();
In the below image you can see
You are skipping to third column. See bellow with two columns per page:
function AcceptPageBreak()
{
if($this->col<1)
{
// Go to next column
$this->SetCol($this->col+1);
// Set ordinate to top
$this->SetY($this->y0);
// Keep on page
return false;
}
else
{
// Go back to first column
$this->SetCol(0);
// Page break
return true;
}
}
I'm stamping my PDF documents with FPDI and TCPDF functions, and I'm trying to figure it out, how can I add a line below the text in Header, and upon the text in footer. Here is my code:
<?php
require_once('lib/tcpdf/tcpdf.php');
require_once('fpdi.php');
$fullPathToFile = "TestClanek6.pdf";
class PDF extends FPDI {
var $_tplIdx;
function Header() {
global $fullPathToFile; //global
if(is_null($this->_tplIdx)) {
// number of pages
$this->numPages = $this->setSourceFile($fullPathToFile);
$this->_tplIdx = $this->importPage(1);
}
if($this->page > 0) {
//$this->SetPrintHeader(true);
$this->SetFont('times', 'I', 11);
$this->SetTextColor(0);
$this->Write(15, "Vol. 1, No. 15, Year: 2015, duff");
$this->Image('logo.png', 100, 2, 75,7);
} //end of IF
$this->useTemplate($this->_tplIdx, 0, 0,200);
} //end of HEADER
function Footer() {
if($this->page > 0) {
$this->SetY(-20);
$this->SetFont('times', 'I', 11);
$this->SetTextColor(0,0,0);
$this->Write(0, "Page", '', 0, 'C');
} //end of if
} // end of footer
} //end of CLASS
// new PDF file
$pdf = new PDF();
$pdf->addPage();
if($pdf->numPages>0) {
for($i=1;$i<=$pdf->numPages;$i++) {
$pdf->endPage();
$pdf->_tplIdx = $pdf->importPage($i);
$pdf->AddPage();
//$pdf->SetPrintHeader(false);
//$pdf->SetPrintFooter(false);
}
}
$file_time = time();
$pdf->Output("$file_time.pdf", "F");//, "I");
echo "Link: '<a href=$file_time.pdf>Stamped article</a>'";
?>
I've tried a lot of things like setPrintHeader(), etc. but nothing what I've found works for me. Could i please somebody to help?
Thank you.
duff
You can use the Line method to draw a line in FPDF. If you want a straight horizontal line, just make sure the ordinates (y values) for the start and end of the line are the same. Something like this for example:
$pdf->Ln(15,$pdf->y,200,$pdf->y);
You would modify the values to suit your needs and insert it in the overridden methods for Header and Footer as appropriate for your application.
Better would be to leave the two methods (Header and Footer) empty. this way you would overwrite the drawing from super-class.
like this:
class EmptyFPDI extends FPDI
{
public function Header()
{
}
public function Footer()
{
}
}
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.