Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    [FPDF] Tabelle e a capo

    devo realizzare un listino con fpdf, in pratica devo stampare una una tabella del db ed incolonnarla, grazie ad uno script di esempio trovato sul sito ci sono riuscito ma adesso non riesco a mandare a capo il testo nelle celle quando raggiunge il margine
    la pagina è questa
    il codice usato per realizzarla è questo

    codice:
    <?php
    require('fpdf.php');
    
    class PDF_MySQL_Table extends FPDF
    {
    var $ProcessingTable=false;
    var $aCols=array();
    var $TableX;
    var $HeaderColor;
    var $RowColors;
    var $ColorIndex;
    
    function Header()
    {
    	//Print the table header if necessary
    	if($this->ProcessingTable)
    		$this->TableHeader();
    }
    
    function TableHeader()
    {
    	$this->SetFont('Arial','B',12);
    	$this->SetX($this->TableX);
    	$fill=!empty($this->HeaderColor);
    	if($fill)
    		$this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]);
    	foreach($this->aCols as $col)
    		$this->Cell($col['w'],6,$col['c'],1,0,'C',$fill);
    	$this->Ln();
    }
    
    function Row($data)
    {
    	$this->SetX($this->TableX);
    	$ci=$this->ColorIndex;
    	$fill=!empty($this->RowColors[$ci]);
    	if($fill)
    		$this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]);
    	foreach($this->aCols as $col)
    		$this->Cell($col['w'],5,$data[$col['f']],1,0,$col['a'],$fill);
    	$this->Ln();
    	$this->ColorIndex=1-$ci;
    }
    
    function CalcWidths($width,$align)
    {
    	//Compute the widths of the columns
    	$TableWidth=0;
    	foreach($this->aCols as $i=>$col)
    	{
    		$w=$col['w'];
    		if($w==-1)
    			$w=$width/count($this->aCols);
    		elseif(substr($w,-1)=='%')
    			$w=$w/100*$width;
    		$this->aCols[$i]['w']=$w;
    		$TableWidth+=$w;
    	}
    	//Compute the abscissa of the table
    	if($align=='C')
    		$this->TableX=max(($this->w-$TableWidth)/2,0);
    	elseif($align=='R')
    		$this->TableX=max($this->w-$this->rMargin-$TableWidth,0);
    	else
    		$this->TableX=$this->lMargin;
    }
    
    function AddCol($field=-1,$width=-1,$caption='',$align='L')
    {
    	//Add a column to the table
    	if($field==-1)
    		$field=count($this->aCols);
    	$this->aCols[]=array('f'=>$field,'c'=>$caption,'w'=>$width,'a'=>$align);
    }
    
    function Table($query,$prop=array())
    {
    	//Issue query
    	$res=mysql_query($query) or die('Error: '.mysql_error()."
    Query: $query");
    	//Add all columns if none was specified
    	if(count($this->aCols)==0)
    	{
    		$nb=mysql_num_fields($res);
    		for($i=0;$i<$nb;$i++)
    			$this->AddCol();
    	}
    	//Retrieve column names when not specified
    	foreach($this->aCols as $i=>$col)
    	{
    		if($col['c']=='')
    		{
    			if(is_string($col['f']))
    				$this->aCols[$i]['c']=ucfirst($col['f']);
    			else
    				$this->aCols[$i]['c']=ucfirst(mysql_field_name($res,$col['f']));
    		}
    	}
    	//Handle properties
    	if(!isset($prop['width']))
    		$prop['width']=0;
    	if($prop['width']==0)
    		$prop['width']=$this->w-$this->lMargin-$this->rMargin;
    	if(!isset($prop['align']))
    		$prop['align']='C';
    	if(!isset($prop['padding']))
    		$prop['padding']=$this->cMargin;
    	$cMargin=$this->cMargin;
    	$this->cMargin=$prop['padding'];
    	if(!isset($prop['HeaderColor']))
    		$prop['HeaderColor']=array();
    	$this->HeaderColor=$prop['HeaderColor'];
    	if(!isset($prop['color1']))
    		$prop['color1']=array();
    	if(!isset($prop['color2']))
    		$prop['color2']=array();
    	$this->RowColors=array($prop['color1'],$prop['color2']);
    	//Compute column widths
    	$this->CalcWidths($prop['width'],$prop['align']);
    	//Print header
    	$this->TableHeader();
    	//Print rows
    	$this->SetFont('Arial','',9);
    	$this->ColorIndex=0;
    	$this->ProcessingTable=true;
    	while($row=mysql_fetch_array($res))
    		$this->Row($row);
    	$this->ProcessingTable=false;
    	$this->cMargin=$cMargin;
    	$this->aCols=array();
    }
    }
    ?>
    e questo sulla pagina ex.php:

    codice:
    <?php
    define('FPDF_FONTPATH','font/');
    require('mysql_table.php');
    
    class PDF extends PDF_MySQL_Table
    {
    function Header()
    {
    	//Title
    	$this->SetFont('Arial','',9);
    	$this->Cell(0,6,'Molinfrutta SRL',0,1,'C');
    	$this->Ln(10);
    	//Ensure table header is output
    	parent::Header();
    }
    }
    
    //Connect to database
    require_once('../Connections/db_comm.php'); 
    mysql_select_db($database_db_comm, $db_comm);
    
    $pdf=new PDF();
    $pdf->Open();
    $pdf->AddPage();
    //First table: put all columns automatically
    $pdf->Table('SELECT * FROM links ORDER BY id_link ASC');
    $pdf->AddPage();
    $pdf->Output();
    ?>
    come mando a capo il testo alla fine della cella epr evitare la sovrapposizione?
    aiuto!

  2. #2
    Moderatore di Server Apache L'avatar di marketto
    Registrato dal
    Sep 2001
    Messaggi
    5,858
    think simple think ringo

  3. #3
    non capisco deve sbaglio però
    ecco la pagina
    il problema è che mi mette le tabelle una alla fine dell'altra anche se è impostato il punto in cui devono apparire ovvero $Y_Table_Position = 26
    guardando la pagina che mi restituisce mi sono accorto che le stampa in quel punto ma nella pagina in cui finisce la tabella precedente.
    aiuto!!!

    ho usato questo codice :

    codice:
    <?php
    //SHOW A DATABASE ON A PDF FILE
    //FILE CREATED BY: Carlos José Vásquez Sáez
    //YOU CAN CONTACT ME: carlos@magallaneslibre.com
    //FROM PUNTA ARENAS, MAGALLANES
    
    define('FPDF_FONTPATH', 'font/');
    require('fpdf.php');
    
    //Connect to your database
    require_once('../Connections/db_comm.php');
    
    //Select the Products you want to show in your PDF file
    mysql_select_db($database_db_comm, $db_comm);
    $query_links = "SELECT nome,link,id_link FROM links ORDER BY id_link ASC";
    $links = mysql_query($query_links, $db_comm) or die(mysql_error());
    
    $totalRows_links = mysql_num_rows($links);
    
    
    
    //Initialize the 3 columns and the total
    $column_id = "";
    $column_nome = "";
    $column_link = "";
    $column_id_link = "";
    
    //For each row, add the field to the corresponding column
    while($row_links = mysql_fetch_array($links))
    {
        $id = $row_links["id_link"];
        $nome = $row_links["nome"];
        $link = $row_links["link"];
        $id_link = $row_links["id_link"];
    
        $column_id = $column_id.$id."\n";
        $column_nome = $column_nome.$nome."\n";
        $column_link = $column_link.$link."\n";
    				$column_id_link = $column_id_link.$id_link."\n";
        }
    mysql_close();
    
    //Convert the Total Price to a number with (.) for thousands, and (, ) for decimals.
    
    //Create a new PDF file
    $pdf=new FPDF();
    $pdf->Open();
    $pdf->AddPage();
    
    //Fields Name position
    $Y_Fields_Name_position = 20;
    //Table position, under Fields Name
    $Y_Table_Position = 26; 
    
    //First create each Field Name
    //Gray color filling each Field Name box
    $pdf->SetFillColor(232, 232, 232);
    //Bold Font for Field Name
    $pdf->SetFont('Arial', 'B', 9);
    $pdf->SetY($Y_Fields_Name_position);
    $pdf->SetX(45);
    $pdf->Cell(20, 6, 'Id', 1, 0, 'L', 1);
    $pdf->SetX(65);
    $pdf->Cell(80, 6, 'Nome', 1, 0, 'L', 1);
    $pdf->SetX(135);
    $pdf->Cell(30, 6, 'Link', 1, 0, 'R', 1);
    $pdf->Ln();
    $pdf->SetX(170);
    $pdf->Cell(30, 6, 'Id_link', 1, 0, 'R', 1);
    $pdf->Ln();
    
    //Now show the 3 columns
    $pdf->SetFont('Arial', '', 9);
    $pdf->SetY($Y_Table_Position);
    $pdf->SetX(45);
    $pdf->MultiCell(20, 6, $column_id, 1);
    $pdf->SetY($Y_Table_Position);
    $pdf->SetX(65);
    $pdf->MultiCell(80, 6, $column_nome, 1);
    $pdf->SetY($Y_Table_Position);
    $pdf->SetX(135);
    $pdf->MultiCell(30, 6, $column_link, 1, 'R');
    $pdf->SetY($Y_Table_Position);
    $pdf->SetX(170);
    $pdf->MultiCell(30, 6, $column_id_link, 1, 'R');
    
    //Create lines (boxes) for each ROW (Product)
    //If you don't use the following code, you don't create the lines separating each row
    $i = 0;
    $pdf->SetY($Y_Table_Position);
    while ($i < $totalRows_links)
    {
        $pdf->SetX(45);
        $pdf->MultiCell(120, 6, '', 1);
        $i = $i +1;
    }
    
    $pdf->Output();
    ?>

  4. #4
    aiuto

  5. #5
    Moderatore di Server Apache L'avatar di marketto
    Registrato dal
    Sep 2001
    Messaggi
    5,858
    Originariamente inviato da nicaragua90
    aiuto
    ciao, nn ho provato il tuo codice, però posso consigliarti un altro link dal quale prendere qualche suggerimento:
    http://www.fpdf.org/en/script/script3.php


    think simple think ringo

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.