473,469 Members | 1,688 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to create pdf files using php?

127 New Member
i have created resume database... i retrieve all the details about a particular candidate from the database. after displaying the results, i want to create a pdf file for that particular candidate...
if i click a link it should generate a pdf that contain all the details about the candidate.

plz help. urgent. thank you.
Jan 7 '11 #1
7 2652
code green
1,726 Recognized Expert Top Contributor
Use a ready built php PDF class.
ezpdf and FPDF are two I am aware of.

Only ever used FPDF which is quite fiddly but a pretty good support site
Jan 7 '11 #2
impin
127 New Member
whats wrong in this code?
the value is not display in the pdf.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require('fpdf\fpdf.php');
  3. include("config.php");
  4.  
  5. $id = @$_GET['id'] ;
  6. $query1="SELECT * FROM candidate where cid='$id'";
  7. $result1=mysql_query($query1);
  8.  
  9. //$row = mysql_fetch_array($result1);
  10. $cname = mysql_fetch_array($result1); 
  11. $cid = mysql_fetch_array($result1); 
  12.  
  13. $pdf=new FPDF();
  14. $pdf->AddPage();
  15. $pdf->SetFont('Arial','B',16);
  16.  
  17. $pdf->Cell(0,10,'Candidate Name'.$cname,0,1);
  18. $pdf->Cell(0,20,'Candidate Id'.$cid,0,1);
  19. $pdf->Output();
  20. ?>
  21.  
How to display data from the database in the pdf. pdf is generating bt no details displayed.plz help
Jan 8 '11 #3
impin
127 New Member
this code working fine. it displays all the vaules from the table. but i want to display only single candidate's details.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require('fpdf\fpdf.php');
  3. include("config.php");
  4.  
  5. $id = @$_GET['id'] ;
  6.  
  7.   $query="SELECT * FROM candidate";
  8.   $result=mysql_query($query);
  9. $num=mysql_numrows($result);
  10.  
  11. $column_cname = "";
  12. $column_cid = "";
  13.  
  14.  
  15. while($row = mysql_fetch_array($result))
  16. {
  17.     $cname = $row["cid"];
  18.     $cid = substr($row["cname"],0,20);
  19.  
  20.     $column_cname = $column_cname.$cname."\n";
  21.     $column_cid = $column_cid.$cid."\n";
  22.  
  23. }
  24.  
  25.  
  26. //$row = mysql_fetch_array($result1);
  27. //$cname = mysql_fetch_array($result1); 
  28.  
  29. $pdf=new FPDF();
  30. $pdf->AddPage();
  31. $pdf->SetFont('Arial','B',16);
  32.  
  33.  
  34. $pdf->Cell(20,6,$column_cname,1);
  35.  
  36. $pdf->Cell(100,6,$column_cid,1);
  37.  
  38.  
  39. $i = 0;
  40.  
  41. while ($i < $num)
  42. {
  43.     $pdf->SetX(45);
  44.     $pdf->MultiCell(120,6,'',1);
  45.     $i = $i +1;
  46. }
  47.  
  48. //$pdf->Cell(0,10,'Name'.$cname,0,1);
  49.  
  50.  
  51. $pdf->Output();
  52. ?>
  53.  
if i change the code like this

Expand|Select|Wrap|Line Numbers
  1. $query="SELECT * FROM candidate where cid="$id";
  2.  
nothing will display... in order to get single candidate details how to change this code. please help.
Jan 8 '11 #4
impin
127 New Member
if i give input in the query as cid='14', it works fine.

Expand|Select|Wrap|Line Numbers
  1. $query="SELECT * FROM candidate where cid='14'";
  2.  
but when i pass the value of cid like and get the value means,
Expand|Select|Wrap|Line Numbers
  1. $id = $_GET['id'] ;
  2.  $query="SELECT * FROM candidate WHERE cid='$id'";
  3.  
i get an error in the pdf.

FPDF error: Some data has already been output to browser, can't send PDF file like this...
Jan 10 '11 #5
code green
1,726 Recognized Expert Top Contributor
You have an echo statement, or code outside php tags, (including blank spaces) somewhere
Jan 10 '11 #6
impin
127 New Member
i corrected those things, but i don't get any result. but the pdf is generated with no data. just display like this.

Name :
Id:
Phone:

but no data from database...
Expand|Select|Wrap|Line Numbers
  1. $query="SELECT * FROM candidate where cid='14'";
  2.  
for this code i get results from database

Name: James
Id:14
Ph:+91 2324343

It works fine. i thing its something in that select query... I'm getting the cid value from the previous page.
Expand|Select|Wrap|Line Numbers
  1. $id = $_GET['id'] ;
  2.  
so please help...
Jan 11 '11 #7
code green
1,726 Recognized Expert Top Contributor
i thing its something in that select query... I'm getting the cid value from the previous page.
You are stabbing in the dark!
Is the problem occurring from the web-form, the query or the PDF?
You need to get some debugging statements in there.
Echo out the contents of variables from the web-form,
the data returned from the query and the PDF data.
At a guess I think the web-form is wrong
Jan 11 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: james545 | last post by:
I am having a problem with ofstream creating files. Sometimes when I run the program, ofstream creates a new file for writing and writes to it. No problem. But sometimes it fails to create the...
9
by: monomaniac21 | last post by:
Hi everyone i'm trying to setup my website to create new webpages dynamically using php but I am have a major problem in that whenever i create a file it is always created locked so that it can...
13
by: Daniel Walzenbach | last post by:
Hi, Imagine the following situation: I have an asp.net application which allows uploading files to a SQL Server 2000 database (Files are stored as type "images"). As a next step I would like to...
1
by: Mamatha | last post by:
Hi friends, I have an application using mutithreads.In that application one threads writes the data in to a file. Another thread reads the data from same file. So some errors while at the time...
2
by: Vanga Sasidhar | last post by:
Already posted the same message but the date and time of my machine was set back. and it was listed under the old date. Thats why I am posting the same message again. Please accept this. ...
7
by: Grace | last post by:
Does it have any ways that asp.net web application can create the file on client computer or get files from client computer? Thanks.
2
by: asenthil | last post by:
i'm trying to read and write files using java... some errors occurs when i'm trying this code.. Error in java: Cannot find symbol location: class java.io.FileOutputStream FileOutputStream...
5
by: reon | last post by:
While we can create files using c++... Is there any code relating to create folders in c++..
0
satyanagendra
by: satyanagendra | last post by:
hi, Can we create DLL using turboc in windows. I am able to create static libraries using turboc. But I don't know how to make DLL files using turboc If it is possible tell me how to make and...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.