SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict Johana Solendhal's Avatar
    Join Date
    Aug 2004
    Location
    Land of the free
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing variables from PHP to PDF - so far so good

    Hola hola my genious friends!

    So far so good, I have sort of gotten FPDF working. But now I am trying to figure out how to pass my variables to the PDF.

    The FPDF tutorial loads the data from a text file. I figure I had to putmy session in the file, but I don'r really know where to go from now.

    Here's what I got:

    PHP Code:
    <?php
    include_once("config.php");
    require(
    '../fpdf.php');


    // Check user logged in already:
    checkLoggedIn("yes");


    class 
    PDF extends FPDF
    {
    //Load data
    function LoadData($file)
    {
        
    //Read file lines
        
    $lines=file($file);
        
    $data=array();
        foreach(
    $lines as $line)
            
    $data[]=explode(';',chop($line));
        return 
    $data;
    }


    //Colored table
    function FancyTable($header,$data)
    {
        
    //Colors, line width and bold font
        
    $this->SetFillColor(223,246,196);
        
    $this->SetTextColor(0);
        
    $this->SetDrawColor(137,162,7);
        
    $this->SetLineWidth(.1);
        
    $this->SetFont('Arial','',11);
        
    //Header
                
    $this->Image('logo-pdf.png',10,8,48);
                
    $this->Ln(15);
        
    $w=array(40,150);
        for(
    $i=0;$i<count($header);$i++)
        
    $this->Cell($w[$i],7,$header[$i],1,0,'C',1);
        
    $this->Ln();
        
    //Color and font restoration
        
    $this->SetFillColor(247,252,234);
        
    $this->SetTextColor(0);
        
    $this->SetFont('Arial','',11);
        
    //Data
        
    $fill=0;
        foreach(
    $data as $row)
        {
            
    $this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
            
    $this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
            
    $this->Ln();
            
    $fill=!$fill;
        }
        
    $this->Cell(array_sum($w),0,'','T');
    }
    }

    $pdf=new PDF();
    //Column titles
    $header=array('','Dados de Cliente');
    //Data loading
    $data=$pdf->LoadData('countries.txt');
    $pdf->SetFont('Arial','',11);
    $pdf->AddPage();
    $pdf->FancyTable($header,$data);
    $pdf->Output();
    ?>

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,454
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    Session

    You want to incorporate the Session with this?
    PHP Code:
    // Check user logged in already:
    checkLoggedIn("yes"); 
    Where is the checkLoggedIn function?

  3. #3
    SitePoint Addict Johana Solendhal's Avatar
    Join Date
    Aug 2004
    Location
    Land of the free
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The session is in the config file that calls a funcions.php file that diffines that function.

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,454
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    Pdf

    Sorry, but I don't know what you're asking. What variables do you want to pass to the class? You say it is "sort of" working, what works and what doesn't? Any error messages?

  5. #5
    SitePoint Addict Johana Solendhal's Avatar
    Join Date
    Aug 2004
    Location
    Land of the free
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to know how do i load the variables? i mean, right now the data that fills the pdf is coming from contries.txt how do I call variables instead?

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,454
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    Pdf

    OK, I see. Right now the method takes a file and creates an array of each line.
    Maybe use another method that takes a string array as an argument, and pass the variables as strings.
    PHP Code:
    .......
    function 
    LoadVarData($strArr)
    {
        
    $data=array();
        foreach(
    $strArr as $line)
            
    $data[]=explode(';',chop($line));
        return 
    $data;

    .......
    $myVars = ($var1$var2$var3)
    $data=$pdf->LoadVarData($myVars);
    ....... 

  7. #7
    SitePoint Addict Johana Solendhal's Avatar
    Join Date
    Aug 2004
    Location
    Land of the free
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks , but i am getting this:

    PHP Code:
    Parse errorparse errorunexpected ',' in /home/public_html/ladmin/encomendas/pdf/tutorial/tuto5.php on line 67 

  8. #8
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,454
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    array

    Sorry, I forgot the declaration syntax. It should be.
    PHP Code:
    $myVars = array($var1$var2$var3); 


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
  •