【问题标题】:Internal linking in tcpdftcpdf 中的内部链接
【发布时间】:2019-04-17 17:23:25
【问题描述】:

我正在使用TCPDF 创建简单的 pdf 文档。

我正在创建一个页面并使用以下代码添加链接

$pdf->addTOCPage();
$link = $pdf->AddLink();
$pdf->SetLink($link, 0, -1);

现在链接设置成功。但是要导航到该页面我应该添加什么? 我尝试了下面的代码,但它什么也没做,

<a href="#Whattoaddhere" style="color:blue;">Return to TOC</a>

【问题讨论】:

  • 在你链接的doc页面上SetLink的第三个参数是一个数字,你为什么要传递一个字符串?
  • @wOxxOm :编辑问题
  • @wOxxOm : 再次编辑

标签: php tcpdf


【解决方案1】:
 // Create a fixed link to the first page using the * character
 $index_link = $pdf->AddLink();
 $pdf->SetLink($index_link, 0, '*1');
 $pdf->Cell(0, 10, 'Link to INDEX', 0, 1, 'R', false, $index_link);

http://www.tcpdf.org/examples/example_045.phps

更新 - 请参阅 tcpdf 库中的此函数 addHtmlLink()。 您可以通过此添加内部链接

 $pdf->addHtmlLink('#'.$index_link, 'hello');

其中'hello'开始锚的名称,第一个参数是链接的标识符。

你的情况

 $pdf->addHtmlLink('#'.$link, 'Whatever you like to name it');

 $html = '<a href="#'.$link.'" style="color:blue;">link name</a>';
 $pdf->writeHTML($html, true, false, true, false, '');

【讨论】:

  • 如何在 writehtml() 中使用它,例如
  • *1代表页码
  • 我的意思是如何通过 导航到 $index_link
  • 是的,我使用它,但我如何在 html 中使用 ..即在 writehtml 函数中使用
  • 是的,我使用它,但它只会显示页码..而不是目录。
猜你喜欢
  • 1970-01-01
  • 2012-03-19
  • 2017-11-22
  • 1970-01-01
  • 2014-01-15
  • 1970-01-01
  • 2013-12-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多