How to generate table of contents using dompdf?

753 views
Skip to first unread message

Nishant Patel

unread,
Jan 15, 2020, 8:08:37 PM1/15/20
to dompdf
I'm wondering how to generate a Table of Contents with the page number in PHP with laravel ?

BrianS

unread,
Jan 20, 2020, 5:01:22 PM1/20/20
to dompdf
This is a bit of a challenge at present since we do not yet support cross references (ref https://github.com/dompdf/dompdf/issues/217).

I have managed to work out a means using a combination of HTML/CSS and tweaking the data held by CPDF prior to generating the actual PDF. You can find it at the link below but note that this was built out for the 0.6.x release so to use it with the current release you would have to tweak it a bit.

Joseph McMurry

unread,
Jul 30, 2020, 12:45:28 PM7/30/20
to dompdf
I've tried to tweak the example linked to for version 0.8.5 but have not had any luck - the placeholders for the page numbers don't get replaced.
I've set 
$options->set('isPhpEnabled', true);
and 
changed 
$font = Font_Metrics::get_font("helvetica", "bold");
to 
$font = $fontMetrics->getFont('helvetica', 'bold');
but no luck.  Any ideas?

Thanks,
Joseph

BrianS

unread,
Aug 19, 2020, 8:12:34 PM8/19/20
to dompdf
Looks like you can just remove that line setting the $font variable completely. I did that and it worked as expected. Any errors logged?
Reply all
Reply to author
Forward
0 new messages