简体   繁体   English

缩放HTML表以适合TCPDF中的PDF页面

[英]Scale an HTML table to fit onto a PDF page in TCPDF

Is it possible to render a HTML table into PDF using TCPDF and scale it to fit the page? 是否可以使用TCPDF将HTML表格呈现为PDF并将其缩放以适合页面? I have many columns in my table. 我的表中有很多列。 Would it be possible to zoom out or scale it down so it fits? 是否可以缩小或缩小以适应它?

彩色表格被PDF页面边缘切断

TCPDF allows you to write HTML. TCPDF允许您编写HTML。 This way, your table structure does not matter. 这样,您的表结构无关紧要。

Example: 例:

$tbl = <<<EOD
<table border="1">
<tr>
<th rowspan="3">Left column</th>
<th colspan="5">Heading Column Span 5</th>
<th colspan="9">Heading Column Span 9</th>
</tr>
<tr>
<th rowspan="2">Rowspan 2<br />This is some text that fills the table cell.</th>
<th colspan="2">span 2</th>
<th colspan="2">span 2</th>
<th rowspan="2">2 rows</th>
<th colspan="8">Colspan 8</th>
</tr>
<tr>
<th>1a</th>
<th>2a</th>
<th>1b</th>
<th>2b</th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
<th>6</th>
<th>7</th>
<th>8</th>
</tr>
</table>
EOD;

$pdf->writeHTML($tbl, true, false, false, false, '');

See Full Full Code | 查看完整的完整代码 | See PDF Output 请参阅PDF输出

Send the page dimensions to avoid that. 发送页面尺寸以避免这种情况。 Set your array variable with width and height like this. 像这样设置宽度和高度的数组变量。

$pageDimension = array('500,300'); //width,height

Substitute this array value where you use this pre-defined TCPDF variable ( PDF_PAGE_FORMAT ) 将此数组值替换为使用此预定义TCPDF变量的位置( PDF_PAGE_FORMAT

Replace PDF_PAGE_FORMAT with $pageDimension 更换PDF_PAGE_FORMAT$pageDimension

You will have to not give your table a custom column width to have the results you want but there will be a lot of wrapping depending on on your content. 你不得不给你的表一个自定义列宽以获得你想要的结果,但是根据你的内容会有很多包装。 i think the better way is to choose a different page type like A3 instead of A4 and landscape it. 我认为更好的方法是选择不同的页面类型,如A3而不是A4,然后将其设置为横向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM