How to create pdf files using php?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • impin
    New Member
    • Jul 2010
    • 127

    How to create pdf files using php?

    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.
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    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

    Comment

    • impin
      New Member
      • Jul 2010
      • 127

      #3
      whats wrong in this code?
      the value is not display in the pdf.
      Code:
      <?php
      require('fpdf\fpdf.php');
      include("config.php");
      
      $id = @$_GET['id'] ;
      $query1="SELECT * FROM candidate where cid='$id'";
      $result1=mysql_query($query1);
      
      //$row = mysql_fetch_array($result1);
      $cname = mysql_fetch_array($result1); 
      $cid = mysql_fetch_array($result1); 
      
      $pdf=new FPDF();
      $pdf->AddPage();
      $pdf->SetFont('Arial','B',16);
      
      $pdf->Cell(0,10,'Candidate Name'.$cname,0,1);
      $pdf->Cell(0,20,'Candidate Id'.$cid,0,1);
      $pdf->Output();
      ?>
      How to display data from the database in the pdf. pdf is generating bt no details displayed.plz help

      Comment

      • impin
        New Member
        • Jul 2010
        • 127

        #4
        this code working fine. it displays all the vaules from the table. but i want to display only single candidate's details.

        Code:
        <?php
        require('fpdf\fpdf.php');
        include("config.php");
        
        $id = @$_GET['id'] ;
        
          $query="SELECT * FROM candidate";
          $result=mysql_query($query);
        $num=mysql_numrows($result);
        
        $column_cname = "";
        $column_cid = "";
        
        
        while($row = mysql_fetch_array($result))
        {
            $cname = $row["cid"];
            $cid = substr($row["cname"],0,20);
            
        	$column_cname = $column_cname.$cname."\n";
            $column_cid = $column_cid.$cid."\n";
           
        }
        
        
        //$row = mysql_fetch_array($result1);
        //$cname = mysql_fetch_array($result1); 
        
        $pdf=new FPDF();
        $pdf->AddPage();
        $pdf->SetFont('Arial','B',16);
        
        
        $pdf->Cell(20,6,$column_cname,1);
        
        $pdf->Cell(100,6,$column_cid,1);
        
        
        $i = 0;
        
        while ($i < $num)
        {
            $pdf->SetX(45);
            $pdf->MultiCell(120,6,'',1);
            $i = $i +1;
        }
        
        //$pdf->Cell(0,10,'Name'.$cname,0,1);
        
        
        $pdf->Output();
        ?>
        if i change the code like this

        Code:
        $query="SELECT * FROM candidate where cid="$id";
        nothing will display... in order to get single candidate details how to change this code. please help.

        Comment

        • impin
          New Member
          • Jul 2010
          • 127

          #5
          if i give input in the query as cid='14', it works fine.

          Code:
          $query="SELECT * FROM candidate where cid='14'";
          but when i pass the value of cid like and get the value means,
          Code:
          $id = $_GET['id'] ;
           $query="SELECT * FROM candidate WHERE cid='$id'";
          i get an error in the pdf.

          FPDF error: Some data has already been output to browser, can't send PDF file like this...

          Comment

          • code green
            Recognized Expert Top Contributor
            • Mar 2007
            • 1726

            #6
            You have an echo statement, or code outside php tags, (including blank spaces) somewhere

            Comment

            • impin
              New Member
              • Jul 2010
              • 127

              #7
              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...
              Code:
              $query="SELECT * FROM candidate where cid='14'";
              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.
              Code:
              $id = $_GET['id'] ;
              so please help...

              Comment

              • code green
                Recognized Expert Top Contributor
                • Mar 2007
                • 1726

                #8
                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

                Comment

                Working...