Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Using PDF.php

  1. #1
    Regular Coder
    Join Date
    Aug 2005
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using PDF.php

    Hi,

    Total newbie question : I found this code PDF.php on www.zend.com .

    I ftp it " as is" to the location where all my other php files are. I then added the foll. in another php file which i want to appear as pdf. Clearly i am doing something wrong because it says headers already sent. All my php files have as the first line <? include("variable.php")?> which contains db data etc.

    PHP Code:

    <? include("variable.php")?>
    <font face="Tahoma" size="2">
    <html>                                      // is this needed ?
    <head>                                      // is this needed ?
    <meta http-equiv="Content-Type"             // is this needed ?
    content="text/html; charset=iso-8859-1">   // is this needed ?

    <?php
    require 'PDF.php';                    // Require the lib.
    $pdf = &PDF::factory('p''a4');      // Set up the pdf object.
    $pdf->open();                         // Start the document.
    $pdf->setCompression(true);           // Activate compression.
    $pdf->addPage();                      // Start a page.
    $pdf->setFont('Courier'''8);      // Set font to arial 8 pt.
    $pdf->text(100100'First page');   // Text at x=100 and y=100.
    $pdf->setFontSize(20);                // Set font size to 20 pt.
    $pdf->text(100200'loandata.php'); // Text at x=100 and y=200.
    $pdf->addPage();                      // Add a new page.
    $pdf->setFont('Arial''BI'12);     // Set font to arial bold italic 12 pt.
    $pdf->text(100100'Second page');  // Text at x=100 and y=200.
    $pdf->output('loandata.pdf');              // Output the file named loandata.pdf
    ?>

    </head>                                // is this needed ?



    <?php
    $sscid 
    $_POST["sscid"];
    $user $_POST["user"];
    $year $_POST["year"];
    $other $_POST["other"];
    $loan $_POST["loan"];
    $days $_POST["days"];
    $cdate $_POST["cdate"];
    list(
    $cyear$cmonth$cday) = explode('-'$cdate);
    $cdate1 $cday."-".$cmonth."-".$cyear ;

    ?>

    <?
    mysql_connect
    ("localhost"$dbname$dbpasswd )
            or die (
    "Unable to connect to server.");

    mysql_select_db($database)
            or die (
    "Unable to select database.");


    $result mysql_query("SELECT * FROM `users` WHERE user='user' ");
    $myrow mysql_fetch_array($result);
    $first_name $myrow["firstname"];
    $last_name $myrow["lastname"];


    echo 
    $first_name; echo "  ";  echo $last_name;
    <
    hr>
    <
    p></strong>Loan Rs.
    <
    strong><?php
    echo $loan;
    ?>
    </strong>
     &nbsp;&nbsp;&nbsp;Days
     : Rs.
    <strong>
    <?php
    echo $days;
    ?>
    </strong>&nbsp; </strong> dated
    <strong><?php
    echo $cdate1 ;
    ?>

    <?php
    mysql_connect
    ("localhost"$dbname$dbpasswd )
            or die (
    "Unable to connect to server.");

    mysql_select_db($database)
            or die (
    "Unable to select database.");

    $sql3 "UPDATE `Contract` SET  `Loan` = $loan , `Days` = $days, `CDate` = '$cdate' WHERE  `SSCID` = $sscid";
    //echo $sql3;

    $result3 mysql_query($sql3) or die (mysql_error());


    ?>
    </body>
    </html>
    Could someone guide me on how I should modify the script ? Thanks.

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    remove the html-code
    + are you trying this with Internet Explorer? there is an IE bug that will generate a header-related error if you have a session_start() in your php-code and then try to stream the pdf to the client.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    Regular Coder
    Join Date
    Aug 2005
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I removed the <html> and </html> tags and yes I am using IE. Is there a way to use it short of changing browsers ?

    Thanks.

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i didn't find any fix.

    the workaround i implemented was:
    - on page 1, serialize the session-collection and store it in the db and get the primary key of the table is stored it in
    - redirect to page2 with the PK in the querystring
    - on page 2 select the stored string and unserialize it. all references to sessionvariables then need to be changed to the array that contains the unserialized string.

    this doesn't cause the IE bug to crash IE.
    By the way, when you are setting up dynamic pdf-generation and you are debugging your pages, make sure you close all browserwindows after you corrected an error. Else, the pdf wount show when you refresh the page.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

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