Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php中的fpdf以pdf格式创建包含包装数据的表_Php_Fpdf - Fatal编程技术网

使用php中的fpdf以pdf格式创建包含包装数据的表

使用php中的fpdf以pdf格式创建包含包装数据的表,php,fpdf,Php,Fpdf,我使用fpdf库在pdf中创建表结构时遇到问题。当某个特定单元的任何数据具有长字符串时,该单元数据将与其他单元数据重叠。 所以整个表的数据都被打乱了。那么pdf格式的数据似乎不正确 任何人请帮助我在pdf中创建表格,根据单元格中的数据自动调整所有单元格 <?php if($_POST['cmbReportType'] == '1') { $fromdate = date_format(date_create($_POST['txtFromDate']), 'd-M-y'); $im

我使用fpdf库在pdf中创建表结构时遇到问题。当某个特定单元的任何数据具有长字符串时,该单元数据将与其他单元数据重叠。 所以整个表的数据都被打乱了。那么pdf格式的数据似乎不正确

任何人请帮助我在pdf中创建表格,根据单元格中的数据自动调整所有单元格

    <?php
if($_POST['cmbReportType'] == '1')
{
$fromdate = date_format(date_create($_POST['txtFromDate']), 'd-M-y');
$import = ociparse($c, "SELECT 
                            t2.membercardno, (t1.firstname||' '||t1.middlename||' '||t1.lastname) as fullname,
                            t3.description,
                            to_char(t2.startdate,'DD-MON-YY') startdate,
                            to_char(t2.expirydate,'DD-MON-YY') expirydate,
                            t2.ramount,
                            t1.address1,
                            t1.address2
                        FROM 
                            useradmin t1, 
                            userplan t2, 
                            plan t3
                        WHERE 
                            t1.memberid = t2.memberid
                        AND 
                            t2.planid = t3.planid
                        AND 
                            t1.branchid = 3
                        AND 
                            t2.startdate >= '$fromdate'
                        ORDER BY t2.membercardno");


OCIExecute($import);
$k=0;
while(OCIFetch($import))
{
    $a[$k]['membercardno'] = ociresult($import,"MEMBERCARDNO");
    $a[$k]['fullname']   = ociresult($import,"FULLNAME");
    $a[$k]['description'] = ociresult($import,"DESCRIPTION");
    $a[$k]['startdate']  = ociresult($import, "STARTDATE");
    $a[$k]['expirydate'] = ociresult($import, "EXPIRYDATE");
    $a[$k]['ramount']  =  ociresult($import, "RAMOUNT");
    $a[$k]['address1'] = ociresult($import, "ADDRESS1");
    $a[$k]['address2'] = ociresult($import, "ADDRESS2");    
    $k++;
}
$resultcount = count($a);

elseif($_POST['rdbReportFormat'] == 'pdf')
{
/***This report view in tabular format.****/
    $pdf=new FPDF();

$pdf->AddPage();
$reportdate = date('d-m-Y');
$filename = $reportdate.'_report.pdf';
$pdf->SetFillColor(255,0,0);
$pdf->SetTextColor(255);
$pdf->SetDrawColor(128,0,0);
$pdf->SetLineWidth(.3);
$pdf->SetFont('Arial', 'B', 6);
// Header
$header=array('Member Card No','Full Name','Description', 'Start Date', 'Expiry Date', 'ramount', 'Address1', 'Address2');
$w = array(25, 35, 35, 15, 18, 15, 30, 30);
for($i=0;$i<count($header); $i++)
    $pdf->Cell($w[$i],7, $header[$i], 1, 0, 'L', true);

$pdf->Ln();

// Reset colour set for data 
$pdf->SetFillColor(224,235,255);
$pdf->SetTextColor(0);
$pdf->SetFont('courier','',7);
$fill=false;
for($i=0;$i<$resultcount;$i++)
{
    $height =6;
    $pdf->Cell($w[0], '$height', $a[$i]['membercardno'], '1', '0', 'L', $fill);
    $pdf->Cell($w[1], '$height', $a[$i]['fullname'], '1', '0', 'L', $fill);
    $pdf->Cell($w[2], '$height', $a[$i]['description'], '1', '0', 'L', $fill);
    $pdf->Cell($w[3], '$height', $a[$i]['startdate'], '1', '0', 'L', $fill);
    $pdf->Cell($w[4], '$height', $a[$i]['expirydate'], '1', '0', 'L', $fill);
    $pdf->Cell($w[5], '$height', $a[$i]['ramount'], '1', '0', 'L', $fill);
    $pdf->Cell($w[5], '$height', $a[$i]['address1'], '1', '0', 'L', $fill);
    $pdf->Cell($w[5], '$height', $a[$i]['address2'], '1', '0', 'L', $fill);
    $pdf->Ln();
    $fill = !$fill;

}   
$pdf->Cell(array_sum($w),0,'','T');
$pdf->Output($filename, 'I');
}
}   
?>

尝试使用multicell()编写问题字段(即描述-无法预测其最大长度的字段)。这将把它们包装成多行

对于每个multicell字段,您需要使用nbLines查看它是否要换行并计算下一行位置。您还需要执行setXY()来设置下一个单元格的开始

以下是nbLines(可在此处找到:):

函数行($w,$txt){
//计算宽度为w的多单元将占用的行数
$cw=&$this->CurrentFont['cw'];
如果($w==0)
$w=$this->w-$this->rMargin-$this->x;
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
$s=str_replace(“\r”,”$txt);
$nb=斯特伦($s);
如果($nb>0和$s[$nb-1]==“\n”)
$nb--;
$sep=-1;
$i=0;
$j=0;
$l=0;
$nl=1;
而($i$wmax)
{
如果($sep==-1)
{
如果($i=$j)
$i++;
}
其他的
$i=$sep+1;
$sep=-1;
$j=$i;
$l=0;
$nl++;
}
其他的
$i++;
}
返回$nl;
}

Hi-欢迎来到SO!如果您能发布一些示例代码,这将非常有帮助。然后我们可以查看它,调整它,并指出可能出现的错误。fpdf中的表有不同的解决方案。查看脚本。您可以在这里找到更复杂的解决方案:
function NbLines($w,$txt) {
//Computes the number of lines a MultiCell of width w will take
$cw=&$this->CurrentFont['cw'];
if($w==0)
    $w=$this->w-$this->rMargin-$this->x;
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
$s=str_replace("\r",'',$txt);
$nb=strlen($s);
if($nb>0 and $s[$nb-1]=="\n")
    $nb--;
$sep=-1;
$i=0;
$j=0;
$l=0;
$nl=1;
while($i<$nb)
{
    $c=$s[$i];
    if($c=="\n")
    {
        $i++;
        $sep=-1;
        $j=$i;
        $l=0;
        $nl++;
        continue;
    }
    if($c==' ')
        $sep=$i;
    $l+=$cw[$c];
    if($l>$wmax)
    {
        if($sep==-1)
        {
            if($i==$j)
                $i++;
        }
        else
            $i=$sep+1;
        $sep=-1;
        $j=$i;
        $l=0;
        $nl++;
    }
    else
        $i++;
}
return $nl;
}