【问题标题】:TCPDF is drawing a line over text and a strikethrough on the textTCPDF 在文本上画一条线并在文本上画一条删除线
【发布时间】:2015-01-28 09:44:07
【问题描述】:

我使用 TCPDF 取得了巨大成功,但遇到了一些我似乎无法修复的问题。

这张图片显示了正在发生的事情。在文本上绘制了线条,并且对文本应用了删除线,我不想要其中任何一个。

这里是代码。我已经用 cell() 和 text() 试过了,得到了相同的结果。除了不需要的线条外,这一切正常。对这里发生的事情有任何想法吗?

TCPPDF 版本为 6.2.5

    $pdf = new TCPDF('L', 'in', array($cardHeight,$cardWidth),TRUE,"UTF-8"); 

    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);
    $pdf->SetMargins(0, 0, 0);
    $pdf->SetAutoPageBreak(FALSE, 0);  
    $pdf->AddPage();

    $cardData = json_decode($this->getData());

    $frontData = $cardData->front->fields;

    foreach ($frontData as $key => $value) {

        $alignment = strtoupper($value->align[0]);
        $w = $value->w/$dpiCorrection;
        $h = $value->h/$dpiCorrection;

        $cmyk = $this->rgb2cmyk( $this->hex2RGB($value->color) );
        $text = trim($value->text);
        $pdf->SetFont($value->font, $value->weight, $value->size);
        $pdf->SetTextColor((int)$cmyk['c'], (int)$cmyk['m'], (int)$cmyk['y'], (int)$cmyk['k']);

        // $pdf->SetXY($value->x/$dpiCorrection, $value->y/$dpiCorrection);
         // $pdf->Cell(
         //     $w,         // width
         //     $h,         // height
         //     $text,      // text
         //     0,          // border
         //     0,          // ln - current postion after call
         //     $alignment, // L, C, R, or justify alignment
         //     0,          // fill 1 = painted, 0 = transparent
         //     '',         // link
         //     0,          // font stretch mode
         //     1,          // 1 = ignore automatic minimum height value
         //     '',         // cell vertical alignment, relative to specified Y value
         //     ''          // text vertical alignment
         //     );
         // $pdf->Cell(0,0,"Testing".$key);

        $pdf->Text($value->x/$dpiCorrection, $value->y/$dpiCorrection, "testing ".$key);
    }

    $filename = storage_path() . '/test.pdf';
    $pdf->output('test', 'D'); // 'D' force download, 'I' show inline

    $headers = array(
      'Content-Type' => 'application/pdf',
    );

这是边框设置为 1 的输出。

【问题讨论】:

  • 只是想注意strikethrough 也可能是底部边框并且文本溢出它,
  • 尝试$pdf->Text($value->x/$dpiCorrection, $value->y/$dpiCorrection, "");会有什么结果?此外,请使用 TCPDF 的确切版本更新您的问题,因为即使是微小的修订也可能有截然不同的怪癖。
  • 如果您将1 传递给边框参数,您的输出看起来会有所不同吗?
  • @MonkeyZeus,您的建议会生成一个空白文档。我使用的是 TCPDF 版本 6.2.5。
  • @maja,我发布了一个边框 =1 的屏幕截图。

标签: php tcpdf


【解决方案1】:

所以我想通了。简单的事情,有点。

在这段代码中,$value->weight 的值是“粗体”。

$pdf->SetFont($value->font, $value->weight, $value->size);

这行不通。似乎 TCPDF 对此非常具体。因此,无论如何,对我来说,最终的答案是这样做:

$fweight = strtoupper($value->weight[0]);
$pdf->SetFont("$value->font", "$fweight", $value->size);

感谢那些为此提供帮助的人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-20
    • 2019-10-23
    • 2017-08-11
    • 2011-09-30
    • 1970-01-01
    相关资源
    最近更新 更多