473,320 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to create pdf files using php?

127 100+
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 2646
code green
1,726 Expert 1GB
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 100+
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 100+
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 100+
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 Expert 1GB
You have an echo statement, or code outside php tags, (including blank spaces) somewhere
Jan 10 '11 #6
impin
127 100+
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 Expert 1GB
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.