Anchor links in TCPDF

A question was posed on StackOverflow regarding html anchor links like ‘#test’, and how you might go about preserving them.  However, it got deleted before I could post my answer.  This is current as of today, May 22, 2013.

If you are using a version of TCPDF less than 5.9.193, links that start with `#` need to be changed to reference a page number and, optionally, Y position.  For example, `#3,4.5` to jump to page 3 at position 4.5.

As of 5.9.193, you can link to named destinations with html links this way.  However, for this to work, you need to add the named destination yourself with the `setDestination` method. [1] So with the example of `#test` you’ll need to have created a named destination called `test` with `setDestination`.

For an example of how this might be used, see the feature request that got it added: Feature request #265 HTML href link to destination or bookmark

[1.] As far as I’ve experienced, these do not seem to work in Firefox’s current PDF.js reader however.

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>