Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: pdf file..anybody can help me?

  1. #1
    Join Date
    Sep 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default pdf file..anybody can help me?

    i have to print out a pdf report. the information in the pdf file coming from the database..how could i do it using php n mysql? i don't know...

    is there anyone who can help me??

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Thumbs up

    posted by syazyan
    i have to print out a pdf report
    Hope you are talking about displaying a PDF report using PHP/MySQL combination.

    You can find my code below for that purpose

    PHP Code:
    <?php
    //PDF file creation
        
    $p PDF_new();

        
    /*  open new PDF file; insert a file name to create the PDF on disk */
        
    if (PDF_begin_document($p"""") == 0) {
                   die(
    "Error: " PDF_get_errmsg($p));
        }

        
    PDF_set_info($p"Creator""pdf.php");
        
    PDF_set_info($p"Author""codeexploiter");
        
    PDF_set_info($p"Title""Report");

        
    PDF_begin_page_ext($p595842"");

        
    $font PDF_load_font($p"Helvetica-Bold""winansi""");

        
    PDF_setfont($p$font10.0);

        
    PDF_set_text_pos($p1810);
        
    PDF_show($p"Company Report");
        
    PDF_continue_text($p,"");




    //Retrieving the information from the database
    $user "root";
    $password "";
    $dbhost "localhost";
    $dbname "PDF";

    $link =  mysql_connect($dbhost$user$passwd);

    if(!
    link)
    {
        
    error_log(mysql_error(), "tmp/phplog.err");
    }
    else
    {
        
    $db mysql_select_db($dbname$link);
        
        if(!
    db)
        {
            
    error_log(mysql_error(), "tmp/phplog.err");
        }
        else
        {
            
    $query "SELECT matter from PDF";    
            
    $result mysql_query($query,$link);

            while(
    $record mysql_fetch_row($result))
            {

                
    PDF_continue_text($p$record[0]);

            }
                
    PDF_end_page_ext($p"");

                
    PDF_end_document($p"");

                
    $buf PDF_get_buffer($p);
                
    $len strlen($buf);

                
    header("Content-type: application/pdf");
                
    header("Content-Length: $len");
                
    header("Content-Disposition: inline; filename=hello.pdf");
                print 
    $buf;

                
    PDF_delete($p);
     
        }

    }

    ?>
    The above code will retrieve some information, the info you want to furnish in the PDF file, from the database and put into the pdf and you can view the pdf file.

    Hope this will help you

  3. #3
    Join Date
    Sep 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by codeexploiter
    Hope you are talking about displaying a PDF report using PHP/MySQL combination.

    You can find my code below for that purpose

    PHP Code:
    <?php
    //PDF file creation
        
    $p PDF_new();

        
    /*  open new PDF file; insert a file name to create the PDF on disk */
        
    if (PDF_begin_document($p"""") == 0) {
                   die(
    "Error: " PDF_get_errmsg($p));
        }

        
    PDF_set_info($p"Creator""pdf.php");
        
    PDF_set_info($p"Author""codeexploiter");
        
    PDF_set_info($p"Title""Report");

        
    PDF_begin_page_ext($p595842"");

        
    $font PDF_load_font($p"Helvetica-Bold""winansi""");

        
    PDF_setfont($p$font10.0);

        
    PDF_set_text_pos($p1810);
        
    PDF_show($p"Company Report");
        
    PDF_continue_text($p,"");




    //Retrieving the information from the database
    $user "root";
    $password "";
    $dbhost "localhost";
    $dbname "PDF";

    $link =  mysql_connect($dbhost$user$passwd);

    if(!
    link)
    {
        
    error_log(mysql_error(), "tmp/phplog.err");
    }
    else
    {
        
    $db mysql_select_db($dbname$link);
        
        if(!
    db)
        {
            
    error_log(mysql_error(), "tmp/phplog.err");
        }
        else
        {
            
    $query "SELECT matter from PDF";    
            
    $result mysql_query($query,$link);

            while(
    $record mysql_fetch_row($result))
            {

                
    PDF_continue_text($p$record[0]);

            }
                
    PDF_end_page_ext($p"");

                
    PDF_end_document($p"");

                
    $buf PDF_get_buffer($p);
                
    $len strlen($buf);

                
    header("Content-type: application/pdf");
                
    header("Content-Length: $len");
                
    header("Content-Disposition: inline; filename=hello.pdf");
                print 
    $buf;

                
    PDF_delete($p);
     
        }

    }

    ?>
    The above code will retrieve some information, the info you want to furnish in the PDF file, from the database and put into the pdf and you can view the pdf file.

    Hope this will help you
    i've read the code...but i don't understand where should i put these code..in a new php page?..how could i know whether the file retrieve the data from db or not..besides the select statement??..

    can u explain more detail??..i'm very new in creating pdf report using php...

  4. #4
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    You seem to be new to PHP in general. I suggest you take the time to get your head around the basics before trying something a little more complex like generating a PDF.If you just want to plow ahead anyway...a couple questions. What does the database look like? what exactly do you expect to happen?

  5. #5
    Join Date
    Sep 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by blm126
    You seem to be new to PHP in general. I suggest you take the time to get your head around the basics before trying something a little more complex like generating a PDF.If you just want to plow ahead anyway...a couple questions. What does the database look like? what exactly do you expect to happen?

    yes..i'm very new in php...i'm not just trying to generate the pdf..now i'm working and i need to generate the pdf...b4 this i've used the php but...not generating the pdf file...that's y i'm asking a detailed explaination..so i can study about it...

    i have a table called "comments" ...what i want to do is...when user click button report...a pdf report containing data from table "comments" will be generated and can be viewed by the user...

  6. #6
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Thumbs up

    You should have a database in which at least a table with some information on it.

    Quoted by: codeexploiter

    //Retrieving the information from the database
    $user = "root";
    $password = "";
    $dbhost = "localhost";
    $dbname = "PDF";
    Quoted by: codeexploiter

    $user = "root";
    you must specify the database user account through which you want to access the table. In my case i've used account root.

    Quoted by: codeexploiter

    $password = "";
    Here you must specify the password for the user account root

    Quoted by: codeexploiter

    $dbhost = "localhost";
    If you are testing this application in a single machine/your machine you can keep it like that or you can replace the localhost with the machine name on which your web server runs.

    Quoted by: codeexploiter

    $dbname = "PDF";
    This is the database name in which i've my table from which i am gathering the information for generating a PDF report. You can replace the name with your own database name.

    Quoted by: codeexploiter

    $query = "SELECT matter from PDF";
    This is based on my table and the field in it. I have a table named PDF in which i have a field matter which contains the data that I want to put into a PDF file.
    You can replace this with your table name and field name.

    Once you make the necessary changes in the code I provided in a way that it is compatible with your settings you can put this into a .PHP page and into the document root of your web server or any folder which is accessible from the document root.

    The assumption here is that the database resides in the same machine of the web server.

    Quoted by: syazyan
    i have a table called "comments" ...what i want to do is...when user click button report...a pdf report containing data from table "comments" will be generated and can be viewed by the user...
    You can mention the action attribute of a form where you have a button so whenever the user clicks that button it will execute the PHP code that I had provided.

    If you know how to invoke a php page using a front-end interface file then this wont' be much difficult for you to implement

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    "if(!db)"

    Shouldn't that be "if(!$db)"?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Thumbs up

    posted by: djr33
    "if(!db)"

    Shouldn't that be "if(!$db)"?
    Yes it should be sorry for the typing mistake. Thanks for pointing it out

  9. #9
    Join Date
    Sep 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i've copy the code n change it according to my db and table..but when user click report button..the following error occur...

    "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE = ''' at line 1"

    this is my select statement..

    $query = "SELECT * FROM comments WHERE rec_date = '$rec_date'";
    $result = mysql_query($query,$link);

    what does it means??...the code error at "where" statement?

  10. #10
    Join Date
    Sep 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy need solution...

    i've done a pdf file...n i've succeed..but the problem is..i just could read n display the first row of data only...how can i view all the row of data based on specific date??

    this is sample of my code...

    <?php
    //include ("../connectdb.pdf");
    include ('class.ezpdf.php');

    $db = @mysql_connect('localhost','root','') or die(mysql_error());

    mysql_select_db('e-account2', $db);
    $query2 = "SELECT * FROM comments WHERE rec_date = '$rec_date'";
    $result2 = mysql_query($query2,$db)or die(mysql_error());
    $query_data2 = mysql_fetch_array($result2);
    $no = $query_data2["no"];
    $usr_cc = $query_data2["usr_cc"];
    $rec_date = $query_data2["rec_date"];
    $rec_time = $query_data2["rec_time"];
    $call_name = $query_data2["call_name"];
    $call_no = $query_data2["call_no"];
    $company = $query_data2["company"];
    $issue = $query_data2["company"];
    $comments = $query_data2["comments"];


    $pdf =& new Cezpdf();
    $pdf->setEncryption('','rc',array('print'));
    $i=$pdf->ezStartPageNumbers(500,720,9,'','',1);

    $uppertext1 = "Record based on Date Call Received";
    $pdf->selectFont('./fonts/Verdana.afm');
    $pdf->setColor(0,0,0);

    $pdf->addText(30,800,9,$uppertext1);

    $data = array(
    array('No'=>$no, 'Agent'=>$usr_cc, 'rec_time'=>$rec_time,'call_name'=>$call_name,'call_no'=>$call_no,
    'company'=>$company, 'issue'=>$issue, 'comments'=>$comments));
    }

    could anybody help me??

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •