【问题标题】:Scale an HTML table to fit onto a PDF page in TCPDF缩放 HTML 表格以适应 TCPDF 中的 PDF 页面
【发布时间】:2012-11-29 08:10:18
【问题描述】:

是否可以使用 TCPDF 将 HTML 表格呈现为 PDF 并对其进行缩放以适应页面?我的表中有很多列。是否可以缩小或缩小以使其适合?

【问题讨论】:

    标签: php tcpdf


    【解决方案1】:

    TCPD 允许您编写 HTML。这样,您的表结构就无关紧要了。

    例子:

    $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

    【讨论】:

    • 我的意思是 .. 表格正好溢出到它的右边 .. 有没有办法让它适合页面?像某种自动适应页面..
    【解决方案2】:

    发送页面尺寸以避免这种情况。 像这样设置数组变量的宽度和高度。

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

    在您使用此预定义 TCPDF 变量 (PDF_PAGE_FORMAT) 的位置替换此数组值

    PDF_PAGE_FORMAT 替换为$pageDimension

    【讨论】:

      【解决方案3】:

      您不必为表格提供自定义列宽以获得您想要的结果,但根据您的内容会有很多包装。我认为更好的方法是选择不同的页面类型,例如 A3 而不是 A4,然后横向放置。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-07-03
        • 2011-11-17
        • 1970-01-01
        • 2013-12-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多