【问题标题】:tcpdf auto size text fieldtcpdf 自动调整大小文本字段
【发布时间】:2013-03-28 09:00:14
【问题描述】:

在我正在创建的表单上让文本字段自动调整大小时遇到​​问题。我在 TextField 的属性中将属性的 textSize 设置为 0,但它似乎只是使用为文档设置的字体。这是我用来创建 TextField 的代码。

$pdf->TextField('description', 195, 32, array('multiline'=>true, 'lineWidth'=>0, 'borderStyle'=>'none', 'textSize'=>0), array('v'=>$description));

【问题讨论】:

    标签: php pdf-generation tcpdf


    【解决方案1】:

    我知道一种可能解决此问题的迂回方法..

    在您的文本字段代码之前,您可以随时尝试您的字体(不是整个文档的默认字体):

    $pdf->SetFont('fontName','',fontSize);
    

    在您的文本字段代码之后,只需将字体设置回您希望文档其余部分的字体即可。

    不确定这是否正是您正在寻找的,但我希望它有所帮助。祝一切顺利。

    【讨论】:

      【解决方案2】:

      我也遇到了这个确切的问题。我花了很长时间才找到解决方案。

      要使字段自动调整文本内容的大小,必须将字段的字体大小设置为 0。看起来 TCPDF 不支持 javascript textSize 选项(见 TCPDF_STATIC::getAnnotOptFromJSProp() 末尾),所以我们必须在字段之前将字体大小设置为 0,并在文本字段之后再次设置回原来的值:

      // Beware to use getFontSize*Pt* and not getFontSize.
      // getFontSizePt gets the size in pt, and getFontSize gets the size in user units
      // (units you gave when you created TCPDF object or default to mm)
      // We need to set it again back with SetFontSize() which takes the font size in pt
      $originalFontSize = $pdf->getFontSizePt();
      $pdf->SetFontSize(0);
      $pdf->TextField($name, $w, $h);
      $pdf->SetFontSize($originalFontSize);
      

      【讨论】:

        猜你喜欢
        • 2015-05-03
        • 1970-01-01
        • 2011-02-28
        • 1970-01-01
        • 1970-01-01
        • 2012-11-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多