在超过页面大小的行中显示大字符串 (FPDF)

发布于 2024-11-18 11:13:50 字数 239 浏览 3 评论 0原文

我想连续显示以下数组。

$header = array('Sl.', 'Session.', 'Time','Filename','Operator Name','Mobile No.','Amount','SSL Status','SSL Time','Operator Status','Op.Time','Reversal Reqd.?');

但它超出了页面大小。

请帮我。

I want to show the following array in a line without break.

$header = array('Sl.', 'Session.', 'Time','Filename','Operator Name','Mobile No.','Amount','SSL Status','SSL Time','Operator Status','Op.Time','Reversal Reqd.?');

But it exceeds the page size.

Please help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灵芸 2024-11-25 11:13:50

我已将此扩展用于 FPDF 类。它引入了 MultiCell 方法(为了我的方便,包含在 OutputLines 方法中)。在此方法中您可以指定最大行数。字符串中任何不适合的部分都将从函数中返回。在这种情况下,您可以创建一个新函数并再次调用 MultiCell,直到它返回 ''

<?

require 'fpdf.php';
// Class voor implementate van handige aanvullende features.
class EPDF extends FPDF {

    function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false, $maxline=0)
    {
        //Output text with automatic or explicit line breaks, at most $maxline lines
        $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 && $s[$nb-1]=="\n")
            $nb--;
        $b=0;
        if($border)
        {
            if($border==1)
            {
                $border='LTRB';
                $b='LRT';
                $b2='LR';
            }
            else
            {
                $b2='';
                if(is_int(strpos($border,'L')))
                    $b2.='L';
                if(is_int(strpos($border,'R')))
                    $b2.='R';
                $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2;
            }
        }
        $sep=-1;
        $shy=-1;
        $shy1=-1;
        $brk=-1;
        $lshy=0;
          $cx = '';
        $i=0;
        $j=0;
        $l=0;
        $ns=0;
        $nl=1;
        while($i<$nb)
        {
            //Get next character
            $c=$s[$i];
            if($c=="\n")
            {
                //Explicit line break
                if($this->ws>0)
                {
                    $this->ws=0;
                    $this->_out('0 Tw');
                }
                $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
                $i++;
                $sep=-1;
                $shy=-1;
                $shy1=-1;
                $brk=-1;
                $cx='';
                $j=$i;
                $l=0;
                $ns=0;
                $nl++;
                if($border && $nl==2)
                    $b=$b2;
                if($maxline && $nl>$maxline)
                    return substr($s,$i);
                continue;
            }
            if($c==' ')
            {
                $sep=$i;
                $ls=$l;
                $ns++;
            }
            // Soft break (­)
            if ($c==$GLOBALS["hyphen"])
            {
                // Afbreektekentje. Onthouden van laatste en voorlaatste positie.
                $shy1=$shy;
                $shy=$i;
                $lshy1=$lshy;
                $lshy = $l;

                $l-=$cw[$c];
            }
            if ($c=='-')
            {
                $brk=$i;
                $ls = $l + $cw[$c];
                $ns++;
                $cy = '-';
            }
            $l+=$cw[$c];
            if($l>$wmax)
            {
                // Woord past niet meer. Kijken of het af te breken is op een hard afbreekstreepje
                if ($brk>$shy)
                {
                    if ($brk>$sep)
                    {
                        $sep=$brk;
                        $cx='-';
                    }
                }
                elseif ($shy > $sep) // Of op een soft afbreekstreepje
                {
                    if ($lshy + $cw['-'] > $wmax)
                    {
                        if ($shy1 > $sep)
                        {
                            $sep = $shy1;
                            $ls = $lshy1;
                            $cx = '-';
                        }
                    }
                    else
                    {
                        $sep = $shy;
                        $ls = $lshy;
                        $cx = '-';
                    }
                }

                //Automatic line break
                if($sep==-1)
                {
                    if($i==$j)
                        $i++;
                    if($this->ws>0)
                    {
                        $this->ws=0;
                        $this->_out('0 Tw');
                    }
                    $this->Cell($w,$h,substr($s,$j,$i-$j).$cx,$b,2,$align,$fill);
                }
                else
                {
                    if($align=='J')
                    {
                        $this->ws=($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0;
                        $this->_out(sprintf('%.3F Tw',$this->ws*$this->k));
                    }
                    $this->Cell($w,$h,substr($s,$j,$sep-$j).$cx,$b,2,$align,$fill);
                    $i=$sep+1;
                }
                $sep=-1;
                $shy=-1;
                $shy1=-1;
                    $cx = '';
                $j=$i;
                $l=0;
                $ns=0;
                $nl++;
                if($border && $nl==2)
                    $b=$b2;
                if($maxline && $nl>$maxline)
                {
                    if($this->ws>0)
                    {
                        $this->ws=0;
                        $this->_out('0 Tw');
                    }
                    return substr($s,$i);
                }
            }
            else
                $i++;
        }
        //Last chunk
        if($this->ws>0)
        {
            $this->ws=0;
            $this->_out('0 Tw');
        }
        if($border && is_int(strpos($border,'B')))
            $b.='B';
        $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
        $this->x=$this->lMargin;
        return '';
    }

    function OutputLines($w, $h, $text, $maxline = 0)
    {
        return $this->MultiCell($w, $h, $text, 0, 'L', false, $maxline);
    }

}

I've used this extension to the FPDF class. It introduces the MultiCell method (for my convenience wrapped in the OutputLines method). In this method you can specify the maximum number of lines. Any part of the string that won't fit, will be returned from the function. In that case you can create a new function and call MultiCell again, until it returns ''.

<?

require 'fpdf.php';
// Class voor implementate van handige aanvullende features.
class EPDF extends FPDF {

    function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false, $maxline=0)
    {
        //Output text with automatic or explicit line breaks, at most $maxline lines
        $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 && $s[$nb-1]=="\n")
            $nb--;
        $b=0;
        if($border)
        {
            if($border==1)
            {
                $border='LTRB';
                $b='LRT';
                $b2='LR';
            }
            else
            {
                $b2='';
                if(is_int(strpos($border,'L')))
                    $b2.='L';
                if(is_int(strpos($border,'R')))
                    $b2.='R';
                $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2;
            }
        }
        $sep=-1;
        $shy=-1;
        $shy1=-1;
        $brk=-1;
        $lshy=0;
          $cx = '';
        $i=0;
        $j=0;
        $l=0;
        $ns=0;
        $nl=1;
        while($i<$nb)
        {
            //Get next character
            $c=$s[$i];
            if($c=="\n")
            {
                //Explicit line break
                if($this->ws>0)
                {
                    $this->ws=0;
                    $this->_out('0 Tw');
                }
                $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
                $i++;
                $sep=-1;
                $shy=-1;
                $shy1=-1;
                $brk=-1;
                $cx='';
                $j=$i;
                $l=0;
                $ns=0;
                $nl++;
                if($border && $nl==2)
                    $b=$b2;
                if($maxline && $nl>$maxline)
                    return substr($s,$i);
                continue;
            }
            if($c==' ')
            {
                $sep=$i;
                $ls=$l;
                $ns++;
            }
            // Soft break (­)
            if ($c==$GLOBALS["hyphen"])
            {
                // Afbreektekentje. Onthouden van laatste en voorlaatste positie.
                $shy1=$shy;
                $shy=$i;
                $lshy1=$lshy;
                $lshy = $l;

                $l-=$cw[$c];
            }
            if ($c=='-')
            {
                $brk=$i;
                $ls = $l + $cw[$c];
                $ns++;
                $cy = '-';
            }
            $l+=$cw[$c];
            if($l>$wmax)
            {
                // Woord past niet meer. Kijken of het af te breken is op een hard afbreekstreepje
                if ($brk>$shy)
                {
                    if ($brk>$sep)
                    {
                        $sep=$brk;
                        $cx='-';
                    }
                }
                elseif ($shy > $sep) // Of op een soft afbreekstreepje
                {
                    if ($lshy + $cw['-'] > $wmax)
                    {
                        if ($shy1 > $sep)
                        {
                            $sep = $shy1;
                            $ls = $lshy1;
                            $cx = '-';
                        }
                    }
                    else
                    {
                        $sep = $shy;
                        $ls = $lshy;
                        $cx = '-';
                    }
                }

                //Automatic line break
                if($sep==-1)
                {
                    if($i==$j)
                        $i++;
                    if($this->ws>0)
                    {
                        $this->ws=0;
                        $this->_out('0 Tw');
                    }
                    $this->Cell($w,$h,substr($s,$j,$i-$j).$cx,$b,2,$align,$fill);
                }
                else
                {
                    if($align=='J')
                    {
                        $this->ws=($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0;
                        $this->_out(sprintf('%.3F Tw',$this->ws*$this->k));
                    }
                    $this->Cell($w,$h,substr($s,$j,$sep-$j).$cx,$b,2,$align,$fill);
                    $i=$sep+1;
                }
                $sep=-1;
                $shy=-1;
                $shy1=-1;
                    $cx = '';
                $j=$i;
                $l=0;
                $ns=0;
                $nl++;
                if($border && $nl==2)
                    $b=$b2;
                if($maxline && $nl>$maxline)
                {
                    if($this->ws>0)
                    {
                        $this->ws=0;
                        $this->_out('0 Tw');
                    }
                    return substr($s,$i);
                }
            }
            else
                $i++;
        }
        //Last chunk
        if($this->ws>0)
        {
            $this->ws=0;
            $this->_out('0 Tw');
        }
        if($border && is_int(strpos($border,'B')))
            $b.='B';
        $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
        $this->x=$this->lMargin;
        return '';
    }

    function OutputLines($w, $h, $text, $maxline = 0)
    {
        return $this->MultiCell($w, $h, $text, 0, 'L', false, $maxline);
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文