Hyperlink in table of contents page

285 views
Skip to first unread message

Dixon MD

unread,
Apr 30, 2013, 7:46:40 AM4/30/13
to dom...@googlegroups.com
I am generating multiple PDF's using dompdf and combine it using PDFTK.
I want to add Hyperlink in table of contents page. How can I do it?

Dixon MD

unread,
Apr 30, 2013, 7:49:59 AM4/30/13
to dom...@googlegroups.com
I mean pointing the Table of Content to its page in that PDF. Clicking the hyperlink need to point its corresponding page.

BrianS

unread,
May 1, 2013, 11:08:25 PM5/1/13
to dom...@googlegroups.com
Adding links after rendering is going to be difficult. One of the issues with regard to dompdf is the way it represents links in the PDF, which is to reference the internal object representing the page you want to link to. I can see the potential of allowing this type of functionality using named destinations, which I believe you could add using the native CPDF methods. However, I don't see a way that you could modify the TOC PDF so that the necessary links can be added.

Dixon MD

unread,
May 8, 2013, 2:59:32 AM5/8/13
to dom...@googlegroups.com
Sample codes below. When I run the first code I am getting notices like : PHP Notice:  Undefined index: C1 in lib/class.pdf.php on line 1213

I am generating PDF seperate and combine it using pdftk.

First PDF generating code

<?php
ob_start();
?>
<html>
<body style="margin:0; padding:0;">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="84" ><a href="#C1">C1</a></td>
  </tr>
  <tr>
    <td height="84" ><a href="#C2">C2</a></td>
  </tr>
  <tr>
    <td height="84" ><a href="#C3">C3</a></td>
  </tr>
  <tr>
    <td height="84" ><a href="#C4">C4</a></td>
  </tr>
</table>
</body>
</html>
<?php
$contents = ob_get_contents();
ob_end_clean();
require_once("dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html($contents);
$dompdf->set_paper('letter', 'landscape');
$dompdf->render();
$dest_file = "hyper1.pdf";
$pdf = $dompdf->output();
file_put_contents($dest_file, $pdf);
?>



Second PDF generating code

<?php
ob_start();
?>
<html>
<body style="margin:0; padding:0;">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="84" ><a name="C1">&nbsp;</a>C1</td>
  </tr>
</table>
<p style='page-break-after: always'></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="84" ><a name="C2">&nbsp;</a>C2</td>
  </tr>
</table>
<p style='page-break-after: always'></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="84" ><a name="C3">&nbsp;</a>C3</td>
  </tr>
</table>
<p style='page-break-after: always'></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="84" ><a name="C4">&nbsp;</a>C4</td>
  </tr>
</table>
</body>
</html>
<?php
$contents = ob_get_contents();
ob_end_clean();
require_once("dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html($contents);
$dompdf->set_paper('letter', 'landscape');
$dompdf->render();
$dest_file = "hyper2.pdf";
$pdf = $dompdf->output();
file_put_contents($dest_file, $pdf);
?>



On Tuesday, April 30, 2013 5:16:40 PM UTC+5:30, Dixon MD wrote:
Reply all
Reply to author
Forward
0 new messages