3

I am new in php, and using first time FPDF for generating pdf file.
I have a database with name test123 and table with named form having four fields id with data type int, Name, Address and Designation with data type Varchar, and the last one is Text with data type longblob.

Data inserted in these fields by a form having textarea.

Problem is that when I want to generate pdf file and import data from database data type blob is not converted. Here is screenshot of my problem just click on the link http://postimg.org/image/qtid90tqb/

Below is the code I am using:

<?php 
require('fpdf/fpdf.php');

//create a FPDF object
$pdf=new FPDF(); 

//set font for the entire document
$pdf->SetFont('Helvetica','B',20);
//$pdf->SetTextColor(50,60,100);

//set up a page
$pdf->AddPage('P'); 
$pdf->SetDisplayMode('default');

//insert an image and make it a link
$pdf->Image('image/logo.gif',100,10,20,0);

//display the title with a border around it
$pdf->SetXY(40,30);
$pdf->SetDrawColor(50,60,100);
$pdf->Write(10,'The Pakistan Credit Rating Agency Limited',0,'C',0);
$pdf->Line(10,40,200,40);

//Set x and y position for the main text, reduce font size and write content
$pdf->SetXY (20,45);
$pdf->SetFontSize(10);
$pdf->SetTextColor(30,30,100);
$pdf->Write(5,'NL FYI s-l4l (PSO-040515)');

$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="test123"; // Database name 
$tbl_name="form"; // Table name

$con = mysqli_connect('localhost','root','');
mysqli_select_db($con,"test123");

$sql="SELECT * FROM form WHERE id = '30'";
$result = mysqli_query($con,$sql);
while($rows= (mysqli_fetch_array($result,MYSQLI_ASSOC)))
{           
    $name = $rows['Name'];
    $address = $rows['Address'];
    $class = $rows['Designation'];
    $phone = $rows['Text'];

    $pdf->SetXY (20,60);
    $pdf->SetFontSize(12);
    $pdf->SetTextColor(0,0,0);
    $pdf->Write(7,$name);
    $pdf->SetXY (20,65);
    $pdf->Write(7,$address);
    $pdf->SetXY (20,70);
    $pdf->Write(7,$class);
    $pdf->SetXY (20,90);
    $pdf->Write(7,$phone);
    $pdf->Ln(); 
}

//Output the document
$pdf->Output('test.pdf','I');     
?>
  • $phone = $rows['Text']; $text = $row['Text']; why are you using Test column two times in different while loop?? – habib ul haq Jun 11 '15 at 12:13
  • @habibulhaq i remove $text = $row['Text']; but its not working yet. –  Jun 11 '15 at 12:17
  • look at this http://stackoverflow.com/questions/948174/how-do-i-convert-from-blob-to-text-in-mysql – habib ul haq Jun 11 '15 at 12:22
  • 1
    Your *$_rows['Text']* is html code that you are outputting with just *->Write()*. You need to use an expanded version of *->WriteHTML()*, for example you could use http://www.fpdf.org/en/script/script42.php – Sean Jun 11 '15 at 12:26
  • @habibulhaq dear i cant understand this topic nad the tag given here is not working in my cae :( –  Jun 11 '15 at 12:46
  • @Sean Dear its shown error. :( –  Jun 11 '15 at 12:47
  • `its shown error`. Not sure what you mean. Also, you have `$html2pdf->WriteHTML($text);`, but I don't see where you have set `$html2pdf` only `$pdf`. Also, you have 2 fetches `while($rows= (mysqli_fetch_array($result,MYSQLI_ASSOC)))` and `while($row= (mysqli_fetch_array($result,MYSQLI_ASSOC)))`. The 2nd one won't have anything to fetch, as the 1st one fetched them all. You either need to query again before fetching, or do a `data_seek()`. – Sean Jun 11 '15 at 13:51

3 Answers3

-1
$s = oci_parse($conn,"SELECT * FROM form WHERE id = '30'");
oci_execute( $s);
$result = array();
while ($row = oci_fetch_array( $s, OCI_ASSOC+OCI_RETURN_NULLS)) {   
$result[] = $row;   }

$pdf->Cell(20,5,'Name',1,0,'C',0);
$pdf->Cell(20,5,$result[]['Name'],1,0,'C',0);
rahman_akon18
  • 336
  • 3
  • 14
-1
$pdf->Output();     
header("Content-Disposition: attachment; filename=filename.pdf");
JoygiveKalai
  • 63
  • 12
-1
<?php
require("DB.php");
$db_handle = new DBController();
$result = $db_handle->runQuery("SELECT * FROM student");
$header = $db_handle->runQuery("SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` 
WHERE `TABLE_SCHEMA`='blog' 
    AND `TABLE_NAME`='student'");

require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',12);      
foreach($header as $heading) {
    foreach($heading as $column_heading)
        $pdf->Cell(90,12,$column_heading,1);
}
foreach($result as $row) {
    $pdf->SetFont('Arial','',12);   
    $pdf->Ln();
    foreach($row as $column)
        $pdf->Cell(90,12,$column,1);
}
$pdf->Output();
?>