dongqu9972 2017-02-22 05:31
浏览 19

FPDF多单元设置垂直

I'm using FPDF and I want to generate tables using MultiCell() since I need the word wrap property of it. Tried Cell() but it can't read the word wrap. If I used MultiCell() property then table all rows shows vertically.

PDF

If I used multicell() so my pdf data shows vertically. Please suggest me how to do vertical to horizontal.

I tried code:

    require('../fpdf.php');

class PDF extends FPDF
{
// Load data
function LoadData($file)
{
    // Read file lines
    $lines = file($file);
    $data = array();
    foreach($lines as $line)
        $data[] = explode(';',trim($line));
    return $data;
}

// Simple table
function BasicTable($header, $data, $pdf)
{
    // Header
    foreach($header as $col)
        $this->Cell(40, 20, $col, 1, 0, 'C', false);
    $this->Ln();
    // Data
    foreach($data as $row)
    {
        foreach($row as $col)
            //$word = str_word_count($col);
            //$this->MultiCell(30, 10,$col, 0, 'J', 0, 1, '', '', true, null, true);
            //$this->word_wrap($pdf,$col);
            //$this->cell(40,6,$col,1);
             $this->MultiCell(40,6,$col,1);
        $this->Ln();
    }
}

}

$pdf = new PDF('P','mm',array(600,600));
// Column headings
$header = array('Waybill', 'Order@No', 'Consignee Name', 'Consignee Pincode', 'Consignee City', 'Weight', 'COD Amount', 'Product', 'Shipping Client', 'Seller Name', 'Seller Pincode', 'Seller City');
// Data loading
$data = $pdf->LoadData('countries.txt');
$pdf->SetFont('Arial','',14);
$pdf->AddPage();
$pdf->BasicTable($header,$data, $pdf);
$pdf->Output();

Or please suggest me how to word wrap the text

  • 写回答

1条回答 默认 最新

  • dsasd12314 2017-02-22 08:18
    关注

    You could use a class called PDF_MC_Table that is in the FPDF scripts page.

    I've used this class for a very long list of PDF reports, and it works very well with text. Just remember that the data should be stored in a two-dimensional array with one row of the table for each $array[$x] position; so using a foreach loop you could print your table rows using the $pdf->Row() function.

    Here is some example code.

    $data[0]['name'] = 'Some string';
    $data[0]['address'] = 'Address of the person';
    $data[0]['telephone'] = 'the telephone number';
    
    $data[1]['name'] = 'Other Person';
    $data[1]['address'] = 'Address of the other person';
    $data[1]['telephone'] = 'Another phone number';
    
    $pdf->SetWidths(array(30,60,30));
    
    $pdf->Row(array('Name','Address','Telephone')); //Set table header
    foreach ($data as $value) {
        $pdf->Row(array($value['name'],$value['address'],$value['telephone']));
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)