Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internal linking in tcpdf

Tags:

php

tcpdf

I am using TCPDF to create simple pdf document.

I am creating a page and adding link using below code

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

Now link is set successfull.But to navigate to that page what should I add ? I tried below code , but it does nothing,

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

like image 298
Vishnu Avatar asked Oct 20 '22 05:10

Vishnu


1 Answers

 // 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

update - refer to this function addHtmlLink() in tcpdf library. You can add a internal link through this

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

where 'hello' begin the name of anchor and and first param being identifier to the link.

In your case

 $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, '');
like image 164
Harish Lalwani Avatar answered Nov 01 '22 17:11

Harish Lalwani