danfickle / openhtmltopdf

An HTML to PDF library for the JVM. Based on Flying Saucer and Apache PDF-BOX 2. With SVG image support. Now also with accessible PDF support (WCAG, Section 508, PDF/UA)!
https://danfickle.github.io/pdf-templates/index.html
Other
1.93k stars 359 forks source link

Creating anchor link to merged PDF attachment #942

Open Zorobay opened 1 year ago

Zorobay commented 1 year ago

Hi!

I'm using OpenHtmlToPdf to generate PDF's from HTML (duh). However, I also need to be able to handle attachments, that is, other PDF's that I will append to the end of the generated document. We fetch these PDF's from a user specified url. This works fine using PdfMergerUtility from PDFBox.

The last page before the appended PDF's will be an overview of the attachments, a table with document titles and number of pages. I want to turn the document titles into anchor links, so that when a user clicks it, it takes them to the correct page for that appended attachment.

For the genereted PDF, we simply use <a href="#some-id"> to create anchor links. How can I get this link to point to a specific page in the final document? Or is there a way I can append the attachments using "only" html, like:

<a href="#my-attachment-1">link to attachment 1</a>

<attachment data="http://www.example.com/example.pdf" id="my-attachment-1"/>

How would you solve this issue? :)

osnard commented 3 months ago

Did you check https://github.com/danfickle/openhtmltopdf/wiki/Embedding-downloadable-files ?