问题描述
我正在使用“ fpdf”库生成pdf,我遇到的问题是,当它从第二行开始到第二页换行时,数组未按相同的顺序显示,并且每条记录占用一页
第一页上的阵列正在正常加载,但是当该阵列需要转到第2页时,从第2页开始每页的阵列中会出现一条记录,直到完成加载整个阵列为止。
factura.PHP
<?PHP
//Activamos el almacenamiento en el buffer
ob_start();
if (strlen(session_id()) < 1)
session_start();
if (!isset($_SESSION["nombre"]))
{
echo 'Debe ingresar al sistema correctamente para visualizar el reporte';
}
else
{
if ($_SESSION['compras']==1)
{
require"../../modelos/Compras/Cotizacion.PHP";
$compras= new Cotizacion();
$rsptav = $compras->cotizacion_cabecera($_GET["id"]);
//Recorremos todos los valores obtenidos
$regv = $rsptav->fetch_object();
require('FacturaConfig.PHP');
$pdf = new PDF_Invoice( 'P','mm','A4' );
$pdf->AddPage();
$cols=array( "#"=>10,"PRODUCTO"=>91,"CANTIDAD"=>16,"VALOR U."=>25,"IVA%"=>12,"IVA"=>14,"SUBTOTAL"=>22);
$pdf->addCols( $cols);
$cols=array( "#"=>"L","PRODUCTO"=>"L","CANTIDAD"=>"C","VALOR U."=>"R","IVA%" =>"R","IVA" =>"R","SUBTOTAL"=>"C");
$pdf->addLineFormat( $cols);
$pdf->addLineFormat($cols);
$y= 89;
$rsptad = $compras->cotizacion_detalle($_GET["id"]);
while ($regd = $rsptad->fetch_object()) {
Static $a = 0;
$a++;
$line = array( "#"=> "$a","PRODUCTO"=> utf8_decode("$regd->nombre_producto"),"CANTIDAD"=> "$regd->cantidad","VALOR U."=> "$regd->precio_ventax2","IVA%" => "$regd->porcentaje2","IVA" => "$regd->iva_calc","SUBTOTAL"=> "$regd->precio_ventax2");
$size = $pdf->addLine( $y,$line );
$y += $size + 2;
}
$pdf->Output();
}
else
{
echo 'No tiene permiso para visualizar el reporte';
}
}
ob_end_flush();
?>
<?PHP
require('../../public/fpdf181/fpdf.PHP');
define('EURO',chr(128) );
define('EURO_VAL',6.55957 );
class PDF_Invoice extends FPDF
{
// private variables
var $colonnes;
var $format;
var $angle=0;
public function header()
{
$this->SetFont('Arial','B','10');
$this->SetX(-40);
$this->write(5,'codigo header');
$this->Image('logo.jpg',20,'','jpg');
$this->Ln(10);
}
public function footer()
{
$this->SetFont('Arial','10');
$this->SetY(-15);
$this->Write(5,'FOOTER');
}
// public functions
function sizeOfText( $texte,$largeur )
{
$index = 0;
$nb_lines = 0;
$loop = TRUE;
while ( $loop )
{
$pos = strpos($texte,"\n");
if (!$pos)
{
$loop = FALSE;
$ligne = $texte;
}
else
{
$ligne = substr( $texte,$index,$pos);
$texte = substr( $texte,$pos+1 );
}
$length = floor( $this->GetStringWidth( $ligne ) );
$res = 1 + floor( $length / $largeur) ;
$nb_lines += $res;
}
return $nb_lines;
}
function addCols( $tab )
{
global $colonnes;
$r1 = 10;
$r2 = $this->w - ($r1 * 2) ;
$y1 = 79;
$y2 = $this->h - 50 - $y1;
$this->SetXY( $r1,$y1 );
$this->Rect( $r1,$y1,$r2,$y2,"D");
$this->Line( $r1,$y1+6,$r1+$r2,$y1+6);
$colX = $r1;
$colonnes = $tab;
while ( list( $lib,$pos ) = each ($tab) )
{
$this->SetXY( $colX,$y1+2 );
$this->Cell( $pos,1,$lib,"C");
$colX += $pos;
$this->Line( $colX,$colX,$y1+$y2);
}
}
function addLineFormat( $tab )
{
global $format,$colonnes;
while ( list( $lib,$pos ) = each ($colonnes) )
{
if ( isset( $tab["$lib"] ) )
$format[ $lib ] = $tab["$lib"];
}
}
function addLine( $ligne,$tab )
{
global $colonnes,$format;
$ordonnee = 10;
$maxSize = $ligne;
reset( $colonnes );
while ( list( $lib,$pos ) = each ($colonnes) )
{
$longCell = $pos -2;
$texte = $tab[ $lib ];
$length = $this->GetStringWidth( $texte );
$tailleTexte = $this->sizeOfText( $texte,$length );
$formText = $format[ $lib ];
$this->SetXY( $ordonnee,$ligne-1);
$this->MultiCell( $longCell,4,$texte,$formText);
if ( $maxSize < ($this->GetY() ) )
$maxSize = $this->GetY() ;
$ordonnee += $pos;
}
return ( $maxSize - $ligne );
}
}
?>
第1页和第2页
第3页 Link
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)