我在打印列表中使用FPDF。目前,我正在使用ClémentLavoillotte的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'=>'');
}
非常感谢任何帮助。谢谢!
-Eli
答案 0 :(得分:-1)
您需要执行width 100%
并设置table-layout auto
并在coloum中添加CSS white-space nowrap
所以要添加表格样式
table {
table-layout: auto;
width: 100%;
}
table td {
white-space: nowrap
}