【问题标题】:TCPDF SetMargins methodTCPDF SetMargins 方法
【发布时间】:2012-01-10 21:00:44
【问题描述】:

我正在努力在 tcpdf 中获得准确的定位。我试图在多个地方使用 SetMargins() ,但我一定误解了这种方法的用法。 它似乎没有像我预期的那样工作。

$pdf->SetFont('helvetica', '', 12);
$pdf->AddPage();
$pdf->SetMargins(10, 10, 10, true); // set the margins 

$html = 'Here is some text';

$pdf->writeHTMLCell(0, 0, '', '', $html, 'LRTB', 1, 0, true, 'L', true); 

$pdf->SetMargins(0, 10, 0, true); // put space of 10 on top 

$pdf->writeHTMLCell(0, 0, '', '', $html, 'LRTB', 1, 0, true, 'C', true);
$pdf->writeHTMLCell(0, 0, '', '', $html, 'LRTB', 1, 0, true, 'R', true);      

$pdf->Output('example_002.pdf', 'I');

我肯定会得到一个输出,但我希望第一个和第二个 writeHTMLCell() 能够重置它们之间的空间。

http://www.tcpdf.org/doc/classTCPDF.html#ab3bbdb7c85ea08d175fd559be6132ba0

文档说第二个参数是上边距。

简而言之,如果有必要,我想弄乱每一行的边距。但我可能为此使用了错误的方法。 我上面的示例似乎完全忽略了该参数。但是左右参数好像没有问题。

【问题讨论】:

    标签: tcpdf


    【解决方案1】:

    请改用 SetY()。这将从页面顶部设置光标位置

    【讨论】:

    • 请解释一下在哪里使用这个函数,它接受什么参数,你有一个例子的链接吗?或指向它的文档的链接?
    • 这是正确答案!谢谢你。这是我用来将上边距设置为零的代码:$pdf->SetY(0, true, true);
    【解决方案2】:

    你可以简单地使用:

    $pdf->Ln()
    $pdf->Ln(15.5)
    

    在两行之间添加垂直空间。

    通常您只设置一次边距 - 在启动 PDF 文档时。 不要使用边距来控制水平/垂直坐标。

    【讨论】:

      【解决方案3】:

      TCPDF SetMargins 方法是:

      SetMargins($left,$top,$right = -1,$keepmargins = false)
      

      所以你可以在AddPage(); 方法之前使用它,如下所示:

      $pdf->SetMargins(10, 20, 10, true);
      $pdf->AddPage();
      //your HTML code here ...
      

      $keepmargins(boolean) 如果为 true,则覆盖默认页边距。

      【讨论】:

        猜你喜欢
        • 2012-01-17
        • 2016-07-09
        • 2020-01-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多