沃梦达 / 编程问答 / php问题 / 正文

Tcpdf中的换行

word wrap in tcpdf(Tcpdf中的换行)

本文介绍了Tcpdf中的换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用tcpdf创建下面的html表的pdf版本。

如何在单元格中自动换行?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <style type="text/css">
        table.frm {
            width: 960px;
            Height:400px;
            margin-left: auto;
            margin-right: auto;
            border-width: 0px 0px 0px 0px;
            border-spacing: 0px;
            border-style: solid solid solid solid;
            border-color: gray gray gray gray;
            border-collapse: collapse;
            background-color: white;
            font-family: Verdana,Arial,Helvetica,sans-serif;
            font-size: 11px;
        }
        table.frm th {
            Width: 120px;
            border-width: 1px 1px 1px 1px;
            padding: 1px 1px 1px 1px;
            border-style: solid solid solid solid;
            border-collapse: collapse;
            border-color: gray gray gray gray;
            background-color: white;
      }
        table.frm td {
            width: 120px;
            height: 80px;
            vertical-align: top;
            border-width: 1px 1px 1px 1px;
            padding: 2px 2px 2px 2px;
            border-style: solid solid solid solid;
            border-collapse: collapse;
            border-color: gray gray gray gray;
            background-color: white;
        }
  </style>
  <title>Weekly Menu</title>
</head>
<body>
    <table  class="frm">
        <tr>
            <th align="center" colspan="8"><b>WEEKLY MENU</b></th>
        </tr>
        <tr>
            <th align="center" colspan="8"><b>Your Name Here</b></th>
        </tr>

        <tr>
            <th></th>
            <th>Monday</th>
            <th>Tuesday</th>
            <th>Wednesday</th>
            <th>Thursday</th>
            <th>Friday</th>
            <th>Saturday</th>
            <th>Sunday</th>
        </tr>
        <tr>
            <td><b>Breakfast</b></td>
            <td>Scrambled Eggs Black Coffee</td>
            <td>Vegetable Omelet Black Coffee</td>
            <td>2  slices Toast Black Coffee</td>
            <td>Cereal w/milk Black Coffee</td>
            <td>Orange Juice Black Coffee</td>
            <td>Cereal w/milk Black Coffee</td>
            <td>Pancakes w/syrup Black Coffee</td>
        </tr>
        <tr>
            <td><b>Lunch</b></td>
            <td>Tuna Salad Sandwich Diet Coke</td>
            <td>Greek Salad Black Coffee</td>
            <td></td>
            <td>Amer Cheese Sandwich Orange Juice</td>
            <td></td>
            <td></td>
            <td></td>

        </tr>
        <tr>
            <td><b>Dinner</b></td>
            <td>Burger Fried Onions Diet Coke</td>
            <td>Steak Fries Diet Sprite</td>
            <td></td>
            <td>Chicken Cutlet Baked Potato Peas</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td><b>Snack</b></td>
            <td>Apple</td>
            <td>Orange</td>
            <td>Sm bag of chips</td>
            <td>Celery Sticks</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    </table>
</body>
</html>

这是tcpdf代码:

$pdf = new TCPDF('Landscape', 'mm', '', true, 'UTF-8', false); 
$pdf->SetTitle('Weekly Menu');
$pdf->SetMargins(15, 7.5, 12.5);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->AddPage();

$pdf->setFormDefaultProp(array('lineWidth'=>0, 'borderStyle'=>'dot', 'fillColor'=>array(235, 235, 255), 'strokeColor'=>array(255,255,250)));
$pdf->SetFont('times', 'BU', 12);

$pdf->cell(250, 8, 'Weekly Menu', 0, 1, 'C');
$pdf->cell(250, 8, $yourname, 0, 1, 'C');
$pdf->SetFont('times', '', 10);
$cw=35;
$ch=25;
$pdf->SetXY(15,50);
$pdf->cell(25,5,'',1,0,'L');
$pdf->cell($cw,5,$day1,1,0,'C');
$pdf->cell($cw,5,$day2,1,0,'C');
$pdf->cell($cw,5,$day3,1,0,'C');
$pdf->cell($cw,5,$day4,1,0,'C');
$pdf->cell($cw,5,$day5,1,0,'C');
$pdf->cell($cw,5,$day6,1,0,'C');
$pdf->cell($cw,5,$day7,1,1,'C');

$pdf->cell(25,$ch,'Breakfast',1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[0]->breakfast,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[1]->breakfast,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[2]->breakfast,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[3]->breakfast,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[4]->breakfast,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[5]->breakfast,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[6]->breakfast,1,1,'L',0,0,false,'','T');

$pdf->cell(25,$ch,'Lunch',1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[0]->lunch,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[1]->lunch,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[2]->lunch,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[3]->lunch,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[4]->lunch,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[5]->lunch,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[6]->lunch,1,1,'L',0,0,false,'','T');

$pdf->cell(25,$ch,'Dinner',1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[0]->dinner,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[1]->dinner,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[2]->dinner,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[3]->dinner,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[4]->dinner,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[5]->dinner,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[6]->dinner,1,1,'L',0,0,false,'','T');

$pdf->cell(25,$ch,'Snack',1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[0]->snack,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[1]->snack,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[2]->snack,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[3]->snack,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[4]->snack,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[5]->snack,1,0,'L',0,0,false,'','T');
$pdf->cell($cw,$ch,$record[6]->snack,1,1,'L',0,0,false,'','T');


EOD;

推荐答案

我做了更多的研究。我需要使用Multicell而不是单元格来使文本自动换行。

这篇关于Tcpdf中的换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Tcpdf中的换行

基础教程推荐