FPDF insert text - php

I have a html form which sends the answers onto a pdf document. Everything is working fine but I would like the questions to be on the pdf document as well.
currently it looks like this on the pdf:
Jurgen
Yes
No
4
No
I would like it to be:
Name: Jurgen
Do you own a vehicle? Yes
etc
(SOLVED)
my current code for the fpdf file:
<?php
class PDF extends FPDF
{
// Page header
function Header()
{
// Logo
$this->Image('images/logo.png', 10, 6, 30);
$this->SetFont('Arial', 'B', 15);
$this->Cell(50);
$this->Cell(90, 10, 'Document Title', 'C');
// Line break
$this->Ln(20);
}
// Page footer
function Footer()
{
$this->SetY(-15);
$this->SetFont('Arial', 'I', 8);
$this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
}
}
?>
<?php
//set the question values
$questions = array(
'name' => "Name: ",
'date' => "Date: ",
'first' => "First Day of Leave: ",
'last' => "Last Day of Leave: ",
'days' => "Number of Days Taken: ",
'email' => "Managers Email: ",
'sig' => "Signed: ",
);
//set the question answers
$date = $_POST['date'];
$first = $_POST['first'];
$last = $_POST['last'];
$days = $_POST['days'];
$email = $_POST['email'];
$sig = $_POST['sig'];
$name = $_POST['name'];
//set the question names
$questionName = $questions['name'];
$questionDate = $questions['date'];
$questionFirst = $questions['first'];
$questionLast = $questions['last'];
$questionDays = $questions['days'];
$questionEmail = $questions['email'];
$questionSig = $questions['sig'];
//Create the PDF
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
//insert questions and answers
$pdf->MultiCell(150,10,sprintf("%s %s", $questionDate, $date));
$pdf->Ln();
$pdf->MultiCell(150,10,sprintf("%s %s", $questionName, $name));
$pdf->Ln();
$pdf->MultiCell(150,10,sprintf("%s %s", $questionFirst, $first));
$pdf->Ln();
$pdf->MultiCell(150,10,sprintf("%s %s", $questionLast, $last));
$pdf->Ln();
$pdf->MultiCell(150,10,sprintf("%s %s", $questionDays, $days));
$pdf->Ln();
$pdf->MultiCell(150,10,sprintf("%s %s", $questionEmail, $email));
$pdf->Ln();
$pdf->MultiCell(50,10,sprintf("%s %s", $questionSig, $sig));
//display pdf
$pdf->Output();
I am still learning about FPDF since their documentation isn't the best. If I have made some mistakes please let me know. Thank you

To do so you can have your question in an associative array where the key matches with name attribute in your html form.
form.html
<form action="your_post.php" method="POST">
<!-- Your first question about age -->
<label>
What's your name?
<input name="name" type="text" />
</label>
<!-- Your second question -->
<label>
How old are you ?
<input name="yo" type="text" />
</label>
<input type="submit" />
</form>
your_post.php
<?php
$questions = array(
'name' => "What's your name?",
'yo' => 'How old are you?'
);
//Get you question and answer about name
$name = $_POST['name'];
$questionName = $questions['name'];
//You can of course use a foreach through $_POST to get every question
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
//Here concatenate $questionName and $name
$pdf->MultiCell(40,10,sprintf("%s %s", $questionName, $name));
$pdf->Output();

i can't help you with that explicit question, but i had to write a script a few days ago, which also creates a pdf.
I found a very nice tool to do this, which i decided to use instead of fpdf. It directly converts html code to a pdf. (you can also link css into it) maybe this can be also interesting for you.
https://github.com/spipu/html2pdf

This should do
<?php
$pdf = new PDF();
$pdf->Cell(20, 10, 'Name : ' . $name . '');
$pdf->Ln();
$pdf->cell(20, 10, 'Do you own a vehicle? : ' . $question1);
$pdf->Ln();
$pdf->Output();
?>
adding header, the problem you facing now
<?php
class PDF extends FPDF
{
// Page header
function Header()
{
// Logo
$this->Image('images/logo.png', 10, 6, 30);
$this->SetFont('Arial', 'B', 15);
$this->Cell(50);
$this->Cell(90, 10, 'Document Title', 'C');
// Line break
$this->Ln(20);
}
// Page footer
function Footer()
{
$this->SetY(-15);
$this->SetFont('Arial', 'I', 8);
$this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
}
}
?>
Update this is how your final code should look
<?php
//set the question values
$questions = array(
'name' => "Name: ",
'date' => "Date: ",
'first' => "First Day of Leave: ",
'last' => "Last Day of Leave: ",
'days' => "Number of Days Taken: ",
'email' => "Managers Email: ",
'sig' => "Signed: "
);
//set the question answers
$date = $_POST['date'];
$first = $_POST['first'];
$last = $_POST['last'];
$days = $_POST['days'];
$email = $_POST['email'];
$sig = $_POST['sig'];
$name = $_POST['name'];
//set the question names
$questionName = $questions['name'];
$questionDate = $questions['date'];
$questionFirst = $questions['first'];
$questionLast = $questions['last'];
$questionDays = $questions['days'];
$questionEmail = $questions['email'];
$questionSig = $questions['sig'];
//Create the PDF
require('fpdf.php');
class PDF extends FPDF
{
// Page header
function Header()
{
// Logo
$this->Image('images/logo.png', 10, 6, 30);
$this->SetFont('Arial', 'B', 15);
$this->Cell(50);
$this->Cell(90, 10, 'Document Title', 'C');
// Line break
$this->Ln(20);
}
// Page footer
function Footer()
{
$this->SetY(-15);
$this->SetFont('Arial', 'I', 8);
$this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
}
}
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);
//insert questions and answers
$pdf->MultiCell(150, 10, sprintf("%s %s", $questionDate, $date));
$pdf->Ln();
$pdf->MultiCell(150, 10, sprintf("%s %s", $questionName, $name));
$pdf->Ln();
$pdf->MultiCell(150, 10, sprintf("%s %s", $questionFirst, $first));
$pdf->Ln();
$pdf->MultiCell(150, 10, sprintf("%s %s", $questionLast, $last));
$pdf->Ln();
$pdf->MultiCell(150, 10, sprintf("%s %s", $questionDays, $days));
$pdf->Ln();
$pdf->MultiCell(150, 10, sprintf("%s %s", $questionEmail, $email));
$pdf->Ln();
$pdf->MultiCell(50, 10, sprintf("%s %s", $questionSig, $sig));
//display pdf
$pdf->Output();

Related

TCPDF Y Position Getting Reset

I am using the TCPDF library to build a PDF to display results of a survey. I have the option to create a custom header to be added to the survey, that can be anything from an image to just text, which can be any size/length.
My problem is on an autobreak the Y position of the following page gets reset and runs with the header.
I am able to change the first page by capturing the current Y position and setting it after the "AddPage()" function. My issue is on the autopagebreaks that occur, I can't find anyway to check if this occurred and trigger something to happen.
I found the "checkpagebreak" but this doesn't work for when the pagebreak occurs during a multicell block of text. I checked the "custom header" example TCPDF has but it appears it uses a static sized header margin, I need to find a way to make that value dynamic.
I am using the following code
// **************************************************************************************
// Process Selection
// **************************************************************************************
function RunReport()
{
// Make all global variables available here
foreach($GLOBALS as $arraykey=>$arrayvalue)
{
if ($arraykey != "GLOBALS")
{
global $$arraykey;
}
}
require_once('tcpdf/tcpdf.php');
class PDF extends tcpdf
{
function Header()
{
//This is pulled from a database but is filled in only to show the current data I am working with***
// $this->S1LDESC = "<center>Test Application<br><img src=\"link/to/image\" width='208'; height='80'></img></center>";
if(trim($this->S1LDESC) <> "")
{
$this->SetFont('Times','',11);
$this->Cell(0, .5, "" , 0,1,'C', 0);
$newX = $this->GetX();
$newY = $this->GetY();
$this->writeHTMLCell(0, .5, $newX, $newY, trim($this->S1LDESC) , 0,1,0, true, 'C', true);
}
$this->SetFont('Times','B',11);
$this->Cell(0, .5, "" , 0,1,'C', 0);
$this->Cell(0, .5, trim($this->S1DESC), 0, 1, 'C', 0, '', 0, false, 'M', 'M');
$this->HeadY = $this->GetY();
$this->SetY($this->GetY() + 5);
}
}
$pdf = new PDF("P", PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SelComp = $SelComp;
$pdf->SelSchool = $SelSchool;
// set auto page breaks
$pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
$pdf->setFontSubsetting(false);
$pdf->SetPrintHeader(true);
$pdf->SetPrintFooter(false);
$pdf->AddPage();
//$pdf->SetY($pdf->HeadY);
$selstring = "SQL To Grab DATA";
if (!($result = db2_exec($db2conn, $selstring, array('CURSOR' => DB2_SCROLLABLE))))
{
echo($selstring."<BR>");
db2_close($db2conn);
die("<b>Error RunReport ". db2_stmt_error().":" . db2_stmt_errormsg()."</b><br>" . $selstring2);
}
while($row = db2_fetch_assoc($result))
{
// make the file field names available in HTML
foreach(array_keys($row) as $key)
{
$escapedField = $key;
$$escapedField = $row[$key];
}
$pdf->SetFont('Times','B',11);
if($HldGroup <> $S2GROUP)
{
$HldGroup = $S2GROUP;
if(trim($S5GROUP) <> "*None")
{
//Write Group data
$pdf->MultiCell(0, 5, trim($S5GROUP), 0, 'L', 0, 1, '', '', true);
if(trim($S5GRPDESC) <> "")
{
$pdf->MultiCell(0, 5, trim($S5GRPDESC), 0, 'L', 0, 1, '', '', true);
}
}
}
if($S2QUESTTYP <> "HD")
{
$pdf->Cell(5, 0, "", 0,0,'C', 0);
$pdf->MultiCell(0, 5, trim($S2QUESTION), 0, 'L', 0, 1, '', '', true);
$pdf->SetFont('Times','',11);
if($S2QUESTTYP <> "ND")
{
$pdf->MultiCell(0, 5, trim($S2QUESTION), 0, 'L', 0, 1, '', '', true);
}
else
{
}
$pdf->MultiCell(0, 5, "", 0, 'L', 0, 1, '', '', true);
}
}
//Print file with Student name and report name???
$pdf->Output("$SurvName.pdf", 'I');
}
This results in the following:
Page 1:
Page 2:

Database Details in PDF are not getting filled?

I am extracting data from MySQL database using php and exporting it as PDF. The columns are not getting filled due to the PDF page size. How do I push the unfilled columns to next line? So that first line has 4 columns and next line has another 4 columns, so on..
<?php
//include connection file
include_once "connection.php";
include_once 'fpdf/fpdf.php';
class PDF extends FPDF {
// Page header
function Header() {
}
// Page footer
function Footer() {
// Position at 1.5 cm from bottom
$this->SetY(-15);
// Arial italic 8
$this->SetFont('Arial', 'I', 8);
// Page number
$this->Cell(0, 10, 'Page '.$this->PageNo().'/{nb}', 0, 0, 'C');
}
}
$db = new dbObj();
$connString = $db->getConnstring();
$id = $_GET['id'];
$query = $connString->prepare("SELECT ID, Name, Wrongs, Rights, Percentage, Age FROM Datas WHERE ID=?");
$query->bind_param('s', $id);
$query->execute();
$result = $query->get_result();
$display_heading = array('ID' => 'ID', 'Name' => 'Name', 'Wrongs' => 'Wrongs', 'Rights' => 'Rights', 'Percentage' => 'Percentage', 'Age' => 'Age');
//$result = mysqli_query($connString, "SELECT ID, Name, Wrongs, Rights, Percentage, Age FROM Datas") or die("database error:". mysqli_error($connString));
$header = mysqli_query($connString, "SHOW columns FROM Datas");
$pdf = new PDF();
//header
$pdf->AddPage();
//foter page
$pdf->AliasNbPages();
$pdf->SetFont('Arial', 'B', 12);
foreach ($header as $heading) {
$pdf->Cell(45, 12, $display_heading[$heading['Field']], 1);
}
foreach ($result as $row) {
$pdf->Ln();
foreach ($row as $column) {
$pdf->Cell(45, 12, $column, 1);
}
}
$pdf->Output();

TCPDF Transaction: Empty font family

I am using TCPDF to generate a PDF and I get the following error when i use transaction:
TCPDF ERROR: Empty font family
I have the following code snippet(with transaction for pagebreak):
$titleDesc = $sPDFQuestion;
$pageNum = $this->pdf->PageNo();
$this->pdf->startTransaction();
$this->pdf->Bookmark($sPDFQuestion, 1, 0);
$this->pdf->titleintopdf($pdfTitle, $sPDFQuestion);
if($pageNum != $this->pdf->PageNo()){
$this->pdf->rollbackTransaction(false);
$this->pdf->AddPage('P', 'A4');
$this->pdf->Bookmark($sPDFQuestion, 1, 0);
$this->pdf->titleintopdf($pdfTitle, $sPDFQuestion);
}
else {
$this->pdf->commitTransaction();
}
This is the function titleintopdf():
public function titleintopdf($title, $description = '')
{
if (!empty($title)) {
$title = $this->delete_html($title);
$oldsize = $this->FontSizePt;
$this->SetFontSize($oldsize + 4);
$this->Line(5, $this->y, ($this->w - 5), $this->y);
$this->ln(3);
$this->MultiCell('', '', $title, '', 'C', 0);
$this->MultiCell('', '', "Number:".$this->PageNo(), '', 'C', 0);
if (!empty($description) && isset($description)) {
$description = $this->delete_html($description);
$this->ln(7);
$this->SetFontSize($oldsize + 2);
$this->MultiCell('', '', $description, '', 'C', 0);
$this->ln(2);
} else {
$this->ln(4);
}
$this->MultiCell('', '', "Number:".$this->PageNo(), '', 'C', 0);
$this->Line(5, $this->y, ($this->w - 5), $this->y);
$this->ln(5);
$this->SetFontSize($oldsize);
}
}
When I don't rollback the transaction and I just commit it instead, everything works fine. I don't have a clue, why this error occurs. Do you know what the problem could be?
Greets!
The error lies in
$this->pdf->rollbackTransaction(false);
'false' means here to not restore $this->pdf to its original state, but to return the original state as a TCPDF object, so correct would be either:
$this->pdf = $this->pdf->rollbackTransaction(false);
or
$this->pdf->rollbackTransaction(true);
The error "TCPDF ERROR: Empty font family" is just a follow-up error of $this->pdf not being valid anymore.

How to display images in pdf using fpdf library?

Currently I am working on opencart. And I have to display data in pdf for that I use FPDF.
my function looks like
public function exportPDF(){
require_once(DIR_SYSTEM . 'lib/fpdf.php');
$pdf = new fpdf();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
$category_id = $this->request->get['id'];
$this->load->model('catalog/product');
$this->load->model('tool/image');
$temp_data = $this->model_catalog_product->getProductscsv($category_id);
foreach($temp_data as $data)
{
if ($data['image']) {
$image = $this->model_tool_image->resize($data['image'], 178, 276);
} else {
$image = $this->model_tool_image->resize('placeholder.png', 178, 276);
}
$data2[] = array(
'product_id' =>$data['product_id'],
'model' =>$data['model'],
'name' =>$data['name'],
'price' =>$data['price'],
'image' =>$image,
);
}
$row = array();
$pdf->SetFont('Arial','',12);
$pdf->Ln();
$pdf->Cell(35,10,'id',1);
$pdf->Cell(35,10,'model',1);
$pdf->Cell(35,10,'name',1);
$pdf->Cell(35,10,'price',1);
$pdf->Cell(35,10,'image',1);
foreach($data2 as $row)
{
$pdf->SetFont('Arial','',10);
$pdf->Ln();
foreach($row as $column)
$pdf->Cell(35,50,$column,1);
}
$pdf->Output();
}
And current output pdf looks like:
My need is I need to display the images in image column instead of link. how can it make possible. I am new to this, and trying for long time.
How to use $pdf->Image(); in the $data2 array. How to display images in image column in the pdf.
Try this,
foreach($data2 as $row)
{
$pdf->SetFont('Arial','',10);
$pdf->Ln();
foreach($row as $key=>$column)
{
if($key == "image"){
$pdf->Cell(35,50,$this->Image($column,$this->GetX(),$this->GetY()),1);
}else{
$pdf->Cell(35,50,$column,1);
}
}
}
and also read this : reference
Try this code
$this->Cell( 35,10, $pdf->Image($image, $pdf->GetX(), $pdf->GetY()), 0, 0, 'L', false );

Generating PDF dynamically through fpdf

I am trying to generate a PDF dynamically using fpdf, but I am finding it very difficult. Only half of the result I could get. I want to generate my PDF like this:
And now I get a result like this:
Here is the code for PDF:
<?php
require('../fpdf/fpdf.php');
error_reporting(-1);
$id = $_GET['order_id'];
$db = new mysqli('localhost','root','','dbnme'); // use your credentials
class INVPDF extends FPDF
{
var $id;
var $today;
var $widths;
var $heads;
var $aligns;
var $formats;
var $db;
var $invTotal = 0;
var $advancePaid = 0;
//constructor
function INVPDF($invno, $db)
{
parent::fpdf();
$this->id = $invno;
$this->db = $db;
$this->today = date('jS M Y');
$this->heads = array('Item', 'UOM', 'Price', 'Qty', 'Disc %', 'Tax', 'Frt', 'Total' );
$this->widths = array (45, 15, 35, 15, 15, 20, 25, 30);
$this->aligns = array ('L','C','L','C','C','R','C', 'C');
$this->formats = array (0,0,0,0,0,1,0,0);
}
//Page header
function Header()
{
//Arial bold 15
//Title
include("../connect.php");
$ss1 = "select orders.sales_order_id, orders.company_id, lead_address.address, lead_address.address_category, lead_address.country, lead_address.state, lead_address.company_id, lead_address.city,lead_address.pin from orders INNER JOIN lead_address ON orders.company_id=lead_address.company_id where lead_address.address_category='Billing' AND orders.sales_order_id='".$_GET['order_id']."'";
$mq1 = mysql_query($ss1) or die(mysql_error());
$rr1 = mysql_fetch_array($mq1);
$billing = $rr1['address'];
list($line1, $line2, $line3) = explode(',',$billing);
$country = $rr1['country'];
$state = $rr1['state'];
$city = $rr1['city'];
$pin = $rr1['pin'];
//list($line1, $line2, $country, $state, $city, $pin) = explode(',',$address);
$ss2 = "select orders.sales_order_id, orders.company_id, lead_address.address, lead_address.address_category, lead_address.country, lead_address.state, lead_address.company_id, lead_address.city,lead_address.pin from orders INNER JOIN lead_address ON orders.company_id=lead_address.company_id where lead_address.address_category='Shipping' AND orders.sales_order_id='".$_GET['order_id']."'";
$mq2 = mysql_query($ss2) or die(mysql_error());
$rr2 = mysql_fetch_array($mq2);
$shipping = $rr2['address'];
$country1 = $rr2['country'];
$state1 = $rr2['state'];
$city1 = $rr2['city'];
$pin1 = $rr2['pin'];
//$email = $rr1['email'];
// $phone = $rr1['phone'];
// $mobile = $rr1['mobile'];
// $this->SetFont('Arial','B',15);
$this->setXY(10,20);
// $this->Cell(0,10,'INVOICE '.$this->id,0,2,'L');
$this->Image('logo.png',20,6,15);
$this->setXY(12,20);
//
$this->SetFont('OpenSans','',7);
$this->Cell(0,10,'Company Name. ',0,2,'L');
$this->Cell(0,0,'Address1, address2',0,2,'L');
$this->Cell(0,8,'city, stte',0,2,'L');
$this->Cell(0,2,'sales#company.com',0,2,'L');
//$this->Image('images/logo.png',10,6,60);
$this->SetFont('OpenSans','',7);
$this->setXY(12,50);
$this->Cell(0,-2,'Shipping Address',$this->id,0,2,0,'L');
$this->SetFont('OpenSans','',7);
$this->setXY(12,52);
$this ->MultiCell(57,22,'', 'LRTB', 'L', 1);
//$this->Cell(0,8,$name,$this->id,0,2,0,'L');
$this->setXY(12,55);
$this->Cell(0,-1,$shipping,$this->id,0,2,0,'L');
$this->setXY(12,53);
$this->Cell(0,10,$country." , ".$state,$this->id,0,2,0,'L');
$this->setXY(12,52);
$this->Cell(0,20,$city." , ".$pin,$this->id,0,2,0,'L');
$this->SetFont('OpenSans','',7);
$this->setXY(140,52);
$this ->MultiCell(57,22,'', 'LRTB', 'L', 1);
$this->setXY(140,34);
$this->Cell(0,30,'Billing Address',$this->id,0,2,0,'L');
$this->SetFont('OpenSans','',7);
$this->setXY(140,35);
$this->Cell(0,40,$line1." , ".$line2, $this->id,0,2,0,'L');
$this->setXY(140,35);
$this->Cell(0,49,$line3, $this->id,0,2,0,'L');
$this->setXY(140,33);
$this->Cell(0,62,$city1." , ".$pin1,$this->id,0,2,0,'L');
$this->setXY(140,33);
$this->Cell(0,70,$country1." , ".$state1,$this->id,0,2,0,'L');
//$this->setXY(12,65);
// $this->Cell(0,60,$phone,$this->id,0,2,0,'L');
//$this->setXY(12,65);
//$this->Cell(0,70,$mobile,$this->id,0,2,0,'L');
$this->SetFont('OpenSans','',7);
$this->setXY(10,5);
$this->Cell(0,10,'QUOTATION: '.$this->id,0,2,'R');
$this->SetFont('OpenSans','',7);
$until = date ('jS F Y', strtotime($this->today));
$this->Cell(0,0,'Date: '.$until,0,2,'R');
$this->SetFont('OpenSans','',7);
$this->Cell(0,10,'Due Date: Due on receipt',0,2,'R');
//Line break
$this->Ln(60);
for ($i=0; $i<9; $i++)
{
$this->Cell ($this->widths[$i], 8, $this->heads[$i], 1, 0, 'C', 1);
}
$this->Ln(8);
}
//Page footer
function Footer()
{
# $this->SetY(-50); // Uncomment to position at 5 cm from bottom
//Arial italic 8
$this->SetFont('OpenSans','',8);
$w = array_sum(array_slice($this->widths,0,3));
$this->Cell($w,12,'',1);
$this->Cell($this->widths[3],12,'',1,0,'C');
$this->setLeftMargin(45 + array_sum(array_slice($this->widths,0,4)));
$this->Cell($this->widths[5],4,'Sub Total',1);
$this->Cell($this->widths[6],4,number_format($this->invTotal,2),1,0,'R');
$this->Cell($this->widths[7],4,'USD',1,1,'C');
$this->Cell($this->widths[5],4,'Tax',1);
$this->Cell($this->widths[6],4,number_format($this->advancePaid,2),1,0,'R');
$this->Cell($this->widths[7],4,'USD',1,1,'C');
$this->Cell($this->widths[5],4,'Freight',1);
$this->Cell($this->widths[6],4,number_format($this->freight,2),1,0,'R');
$this->Cell($this->widths[7],4,'USD',1,1,'C');
$this->setLeftMargin(10);
$this->Cell($this->widths[5],4,'Total',1);
$this->Cell($this->widths[6],4,number_format($this->invTotal+$this->advancePaid,2),1,0,'R');
$this->Cell($this->widths[7],4,'USD',1,1,'C');
$this->SetFont('OpenSans','',6);
$this->Cell($w,10,'',0,0,'L');
$this->Cell(30,4,'Private Limited Company - TIN: 345sddd - PAN: sf43534',0,0,'C');
//$this->Cell($w,10,'');
$this->Cell(-30,12,'SRVC TAX: gddddddddddd - CIN: sdgdgdgdfgfdgfg',0,0,'C');
$this->Cell(30,20,'This document has been electronically generated and requires no physical signature or stamp.',0,0,'C');
}
function makeInvoice()
{
$sql = "select before_order_line_items.item, before_order_line_items.description, before_order_line_items.uom, before_order_line_items.selling_price, before_order_line_items.quantity, before_order_line_items.discount, before_order_line_items.tax, before_order_line_items.freight, before_order_line_items.tax_amount, before_order_line_items.total, items.name as iname, taxes.tax_id, taxes.name as tname, taxes.rate from before_order_line_items inner join items on before_order_line_items.item=items.item_id inner join taxes on before_order_line_items.tax=taxes.tax_id where before_order_line_items.sales_order_id = '".$_GET['order_id']."' ";
//echo $sql;
$res = $this->db->query($sql) or die($this->db->error);
$this->SetFont('OpenSans','',8);
if ($res->num_rows > 0)
{
while ($r = $res->fetch_row())
{
$this->invTotal += $r[10];
foreach ($r as $c => $value) {
//echo $value;
if ($this->formats[$c]) {
$value = number_format($value);
// echo $value;
}
$this->Cell($this->widths[$c],10,$value,'LR',0, $this->aligns[$c]);
}
$this->Ln();
//$amount = number_format($amount+$value);
}
}
}
} # invpdf class
$invno = $_GET['order_id'];
//Instantiation of inherited class
$pdf = new INVPDF($invno, $db);
$pdf->Open();
$pdf->AliasNbPages();
$pdf->setLeftMargin(10);
$pdf->setRightMargin(10);
$pdf->AddFont('OpenSans','','Opensans-Regular.php');
$pdf->SetFont('OpenSans','',7);
$pdf->SetDrawColor(102);
$pdf->SetFillColor(220);
$pdf->AddPage();
$pdf->makeInvoice();
$pdf->Output();
?>
Can somebody please help me how to do it? or is there any example code for something similar to this?
Looking at your actual pdf and expected pdf.. you are missing the no. column in table header.
This line-
$this->heads = array('Item', 'UOM', 'Price', 'Qty', 'Disc %', 'Tax', 'Frt', 'Total' );
should be-
$this->heads = array('No.', 'Item', 'UOM', 'Price', 'Qty', 'Disc %', 'Tax', 'Frt', 'Total' );

Categories