eKoopmans / html2pdf.js

Client-side HTML-to-PDF rendering using pure JS.
MIT License
4.15k stars 1.39k forks source link

Linking a Table of Contents page to sections of the PDF #395

Open romucci opened 3 years ago

romucci commented 3 years ago

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.

cablegunmaster commented 3 years ago

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.

romucci commented 3 years ago

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

jxmot commented 3 years ago

@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.

suhoy commented 2 years ago

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

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

WISEFREAKZ commented 2 years ago

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

sursasundar commented 4 months ago

@WISEFREAKZ @romucci @suhoy Have you found the solution? Thanks in advance!