【问题标题】:Merge 2 Functions in FPDF在 FPDF 中合并 2 个函数
【发布时间】:2017-08-30 10:55:07
【问题描述】:

我在打印列表中使用FPDF。目前,我正在使用 Clément Lavoillotte 的 WriteHTML 脚本,因此我可以在表格中使用 HTML 标记。但是,我也想包装长文本以适合单元格。我正在考虑将 Olivier 的 Table with MultiCells 脚本与我现在拥有的脚本合并,但我无法让它发挥作用。

这是我遇到问题的 PDF 之一。

如何使长文本适合它所在的单元格?

这是我的代码:

private function generate_picklist($bu_id,$ids,$isdebug=false){
    if (!$this->ion_auth->logged_in()) { echo  'access denied'; exit; }
    ob_start();
    //Create PDF
    require('application/libraries/htmltopdf/WriteHTML.php');

//SAVE THE PICKLIST NUMBER ON ITEMS
//GENERATE PICKLIST NUMBER
$len = "10";
$pick_list_no = '';
$pick_list_no = $code=sprintf("%0".$len."d", mt_rand(1, str_pad("", $len,"9")));

    $get_pick_list = $this->PrintModel->get_pick_list($bu_id, $ids, $pick_list_no);

    $pdf=new PDF_HTML();

    $pdf->AliasNbPages();
    $pdf->SetAutoPageBreak(true, 15);
    $pdf->PageNo();
    $pdf->addPage('L');

    $this->pdf_header($pdf,$bu_id,'Pick List','Date:  '.date("Y/m/d"), '', 'PL #: '.$get_pick_list[0]['picklist_no']);

    $rc_y = 20; 

    $pdf->SetXY(10,$rc_y + 40);

    $header = array(array('name'=>'Date Received','width'=>45),
                    array('name'=>'Customer Name','width'=>45),
        array('name'=>'Vendor','width'=>30),
                    array('name'=>'Item','width'=>45),
                    array('name'=>'Quantity','width'=>25),
                    array('name'=>'Price','width'=>30),
        array('name'=>'Shelf #','width'=>30),
    );
    $row_ht = 7;

    // Header
    $pdf->SetFillColor(51, 122, 183);
    $pdf->SetTextColor(255);
    $pdf->SetDrawColor(0,0,0);//$pdf->SetDrawColor(128,0,0);
    $pdf->SetLineWidth(.1);
    $pdf->SetFont('Arial','',11);
    for($i=0;$i<count($header);$i++) {
        $pdf->Cell($header[$i]['width'],$row_ht,$header[$i]['name'],1,0,'C',true);
    }
    $pdf->Ln();

    // ROW  Color and font restoration
    $pdf->SetFillColor(224, 235, 255);
    $pdf->SetTextColor(0);
    $pdf->SetFont('Arial','',9);
    // Data
    $fill = false; $crt = 1; $lnt = count($boxes);

    foreach($get_pick_list AS $get_pick_list_data){
        $brdr = 'LR';
        if ($crt == $lnt) $brdr = 'LRB';


        $pdf->Cell($header[0]['width'],$row_ht,' '.$get_pick_list_data['date_received'],$brdr,0,'C',$fill);
        $pdf->Cell($header[1]['width'],$row_ht,' '.$get_pick_list_data['customer_name'],$brdr,0,'L',$fill);
  $pdf->Cell($header[2]['width'],$row_ht,' '.$get_pick_list_data['vendor_name'],$brdr,0,'L',$fill);
        $pdf->Cell($header[3]['width'],$row_ht,' '.$get_pick_list_data['item_description'],$brdr,0,'L',$fill);
        $pdf->Cell($header[4]['width'],$row_ht,' '.$get_pick_list_data['qty']   ,$brdr,0,'C',$fill);
        $pdf->Cell($header[5]['width'],$row_ht,' '.$get_pick_list_data['price'],$brdr,0,'R',$fill);
  $pdf->Cell($header[6]['width'],$row_ht,' '.$get_pick_list_data['shelf_no'],$brdr,0,'C',$fill);

        $pdf->Ln();
        $fill = !$fill;
        $crt +=1;
    }
    // Closing line
$pdf->Cell(250, 0, '', 'T');
    if ($isdebug==true){
        $path_to_pdf = 'assets/pdf/picklist.pdf';

        if (file_exists($path_to_pdf))  {   unlink($path_to_pdf); }
        $pdf->Output($path_to_pdf,'D');
        ob_end_flush();
    } else {
        $path_to_pdf = 'assets/pdf/picklist-'.'xx'.'.pdf';
        $pdfdoc = $pdf->Output($path_to_pdf, "F");
        ob_end_flush();
    }
    return array('status'=>1, 'msg'=>'');
}

非常感谢任何帮助。谢谢!

-伊莱

【问题讨论】:

    标签: php html pdf fpdf


    【解决方案1】:

    你需要做width 100%并设置table-layout auto还在coloum中添加CSSwhite-space nowrap

    所以添加表格样式来跟随

     table {
            table-layout: auto;
            width: 100%;
     }    
     table td {
           white-space: nowrap 
     }
    

    【讨论】:

    • 感谢您的回答。但是我应该在哪里添加 CSS?
    • 你正在使用 WriteHTML(fpdf.org/en/script/script42.php) 所以你可以在头部添加&lt;style&gt;标签添加你的css
    • 你也可以写内联css
    • 我正在使用 CodeIgniter 并且没有实际文件,所以我不确定在哪里添加内联 CSS。稍后我会添加上面的代码。
    • 请尝试$pdf-&gt;MultiCell(75,7,’Insert your long string here’,1,’L’,false); MultiCell 基本上允许打印带有换行符的文本。参数信息请查看fpdf.org/en/doc/multicell.htm
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多