View Single Post
  #7 (permalink)  
Old 06-09-09, 11:15 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 2,659
Thanks: 0
Thanked 22 Times in 22 Posts
Quote:
Originally Posted by sharyjunco View Post
Hey job0107,

Your post on php scripts were very helpful, would you know how to set up your scripts to offer 2 columns? I like the result of the layout but I need to make my document in 2 columns so I can fit everything into 1 page. I've been trying to find scripts that can layout the received pdfs nicely but nothing is working.

Thanks a bunch!

Shary
The $data array is a multidimensional array, arranged by row and column.
So the inner arrays represent the columns.
And the more elements you have in the inner arrays, the more columns you will have.

This version of the $data array is set up with three rows and two columns.
PHP Code:
<?php
require('fpdf.php');

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;
  }

 
//Simple table
 
function BasicTable($header,$data,$column_width)
 {
  
//Header
  
if($header)
  {
   foreach(
$header as $col)
    
$this->Cell(20,7,$col,1);
   
$this->Ln();
   }
  
//Data
  
foreach($data as $row)
  {
   foreach(
$row as $col)
    
$this->Cell($column_width,10,$col,1); // Change the value 10, to change the height of the rows.
   
$this->Ln();
   }
  }
 }

$pdf=new PDF();
//Data loading
$data = array();

// This configuration gives you three rows and two columns. //
$data[] = array($_POST["field_01"],$_POST["field_02"]);
$data[] = array($_POST["field_03"],$_POST["field_04"]);
$data[] = array($_POST["field_05"],$_POST["field_06"]);

// This would be two rows and three columns. //
/*
$data[] = array($_POST["field_01"],$_POST["field_02"],$_POST["field_03"]);
$data[] = array($_POST["field_04"],$_POST["field_05"],$_POST["field_06"]);
*/
//////////////////////////////////////////////

// And this would be one row and six columns. //
/*
$data[] = array($_POST["field_01"],$_POST["field_02"],$_POST["field_03"],$_POST["field_04"],$_POST["field_05"],$_POST["field_06"]);
*/
//////////////////////////////////////////////

$pdf->SetFont('Arial','',14);
$pdf->AddPage();
$pdf->BasicTable("",$data,50);  // Change the value 50, to change the width oh the columns.

// Disable this line and enable the next line to output to a file. //
$pdf->Output();
// $pdf->Output("myFile.pdf","F");
?>
__________________
Jerry Broughton
Reply With Quote