简体   繁体   English

如何使用单元格方法在带有 TCPDF 的 pdf 上添加链接?

[英]How can I add link on pdf with TCPDF using cell method?

I'm trying to create an external link on pdf file generated by TCPDF library using Cell method.我正在尝试使用 Cell 方法在由TCPDF库生成的 pdf 文件上创建外部链接。 I've written code something like this:我写了这样的代码:

$this->pdf = new PDF();
$this->pdf->Cell(20, 10, 'Click here', 1, 0, 'L', true, 'https://example.com', 1, false, 'T', 'C');

The above code simply print the text and doesn't create a link however, if I include the link along with text on the third argument as below then only it creates a link:上面的代码只是打印文本并且不创建链接但是,如果我在第三个参数中包含链接以及文本,如下所示,那么它只会创建一个链接:

$this->pdf = new PDF();
$this->pdf->Cell(20, 10, 'Click here https://example.com', 1, 0, 'L', true, 'https://example.com', 1, false, 'T', 'C');

I've also tried the accepted solution from this thread but it didn't work for me either.我也尝试了这个线程中接受的解决方案,但它也对我不起作用。

Can anyone help?任何人都可以帮忙吗? Thanks!谢谢!

Working code工作代码

I cannot reproduce the issue with using tcpdf 6.4.4:我无法重现使用tcpdf 6.4.4 的问题:

composer.json作曲家.json

{
    "require": {
        "tecnickcom/tcpdf": "^6.4"
    }
}

test.php测试.php

require_once __DIR__ . "/vendor/autoload.php";

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

$pdf->AddPage();

//Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=0, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M')
$pdf->Cell(20, 10, 'Click here', 1, 0, 'L', false, 'https://example.com', 1, false, 'T', 'C');
$pdf->Output('example_004.pdf', 'I');

Output输出

Can you tell me which version of the library you are using?你能告诉我你使用的是哪个版本的库吗?

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

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