php tcpdf 中的自动换行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2938953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:12:02 来源:igfitidea点击:
word wrap in tcpdf
提问by ChuckO
I'm using tcpdf to creat a pdf version of the html table below.
我正在使用 tcpdf 创建下面 html 表的 pdf 版本。
How do I word wrap the text in the cells?
如何让单元格中的文本自动换行?
<!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>
This is the tcpdf code:
这是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;

