TCPDF如何链接到目录(TOC)? [英] TCPDF How do you make a link to the Table of Contents (TOC)?

查看:158
本文介绍了TCPDF如何链接到目录(TOC)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以演示一个基本示例,在pdf中的任意页面上添加一个链接,将用户带回到目录中吗?

Can anyone demonstrate a basic example that adds a link on an arbitrary page in the pdf that takes the user back to the table of contents?

我的一切工作正常,但不能满足这个简单的要求。

I have everything working fine, but can't get this simple requirement going.

一些背景:

你认为这将是微不足道的,关于TCPDF的一切看起来运作得很好,也许是我糟糕的一天。我尝试了以下内容:

You'd think this would be trivial, everything about TCPDF seems to function so well, maybe a bad day I'm having. I have tried the following:

从文档中可以看出有两个创建内部文档链接的选项

From the documentation there seems to be 2 options for creating internal document links


  • 通过方法addlink()和setlink()来指定目标页面。

  • 通过pdf中呈现的html锚标记(您在其中指定href属性为例如第15页第15页。)

这些方法基本上可以正常工作。

These methods basically work just fine.

作者的引用 -

在当前页面上创建内容列表页面,然后将其移动到指定的页面...创建一个指向TOC页面的链接,你必须设置到最后一页的链接(你必须知道之前的总页数)。

我明白了这个,我最后创建了TOC(使用提供的方法),并链接到最后一页,但它是不可点击的(不是渲染文档中的链接)。因此,我必须解释引用'你必须知道之前的总页数',因为TCPDF必须知道页数!显然是一个很大的区别,对于大多数实际目的而言,答案是否定的,不是通过这种方法(可能是最后一页上的一个链接!)

I Understand this, I create the TOC last (using the supplied methods), and make a link to this last page, but it is unclickable (not a link in the rendered doc). I therefore have to interpret the quote 'you must know the total number of pages before' as meaning TCPDF must know the number of pages! Clearly a big difference, meaning for most practical purposes the answer is no, not by this method (maybe one link on the last page!)

最后,文档为addTOC方法提到$ toc_name参数:

Finally, the documentation for the addTOC method mentions the $toc_name argument:

TCPDF::addTOC   (       
 $page = '',
 $numbersfont = '',
 $filler = '.',
 $toc_name = 'TOC',
 $style = '',
}   

$toc_name (string) name to use for TOC bookmark.

不幸的是我无论如何都看不到在任何地方使用此名称,没有文档,帮助或示例。

Unfortunately I can't see anyway to use this name, no docs, help or examples anywhere.

有人..请告诉我,我很傻..

Someone.. please tell me I'm being silly..

推荐答案

可能会迟到,但这是我使用的(我的目录在第2页):

It may be late, but this is what I use (my table of contents is on page 2):

$pdf->addTOCPage();             
$link = $pdf->AddLink();
$pdf->SetLink($link, 0, '*2');
$pdf->addTOC(2, 'courier', '.', 'INDEX', 'R', array(128,0,0));
$pdf->endTOCPage();

然后在我想要链接回文档中的TOC的地方,我执行以下操作:

And then at where ever I want to link back to the TOC in the document, I do the following:

$html = '<a href="#*2" style="color:blue;">Return to TOC</a>';
$pdf->writeHTML($html, true, false, true, false, 'R');

这篇关于TCPDF如何链接到目录(TOC)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆