html2pdf.js icon indicating copy to clipboard operation
html2pdf.js copied to clipboard

Linking a Table of Contents page to sections of the PDF

Open romucci opened this issue 4 years ago • 6 comments

I am creating a separate Table of Contents page that is bundled inside the PDF which has link tags as:

<a href="#sectionInPDF">
   Go to Section
</a>

and then adding an a tag with the target , which also gets embedded in the PDF

<a name="sectionInPDF">You should arrive here</a>

when saving the PDF file, it doesn't go the section as expected, it opens up a tab in the browser with the anchor tag.

romucci avatar Feb 12 '21 23:02 romucci

https://bunchoblokes.org/pdf/General-Documents/BOB-Manual.pdf#page=4 Well for the A href + links its not the same as HTML. I check online and see this goes like: "#page=" This is the best way to refer to a page number.

cablegunmaster avatar Feb 18 '21 08:02 cablegunmaster

@cablegunmaster The main issue is that it any anchor tag sends me to a new tab, not to an element target inside the PDF

romucci avatar Feb 21 '21 19:02 romucci

@romucci I've found the same issue. All anchor links are incorrect. They're rendered with the base URI preceding the #.

But that's not all.... It appears that all links <a> are broken.

jxmot avatar Mar 20 '21 20:03 jxmot

@romucci it may happened if you set base url before converting to pdf

converterProperties.setBaseUri(baseUrl); HtmlConverter.convertToPdf(html, target, converterProperties);

suhoy avatar Jan 18 '22 16:01 suhoy

@romucci Did you find a solution to this? Thanks in advance!

WISEFREAKZ avatar Feb 08 '22 11:02 WISEFREAKZ