Closed rgarg-atheer closed 2 years ago
Good question :) I never thought about this. Do you mean links to websites or Links within the document?
Links to websites
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hi, This has been open for a while, I'd be interested in looking into this/doing some research. PDFBox offers hyperlink capability (see here https://stackoverflow.com/questions/21021502/how-to-add-hyperlink-in-pdf-using-pdfbox). So I guess it is a matter of including it in pdf-layout. I think links should work (at least) for image and text objects - but since ph-pdf-layout implements a nice object hierarchy I think the best would be to make it work for any object (PLElement?) in the pdf document.
I think the API could be roughly something like:
new PLExternalLink (new PLText ("sometext", r10)).setHref("http://www.foo.com");
new PLExternalLink (new PLImage (ImageIO.read (ClassPathResource.getInputStream ("images/test1.jpg")), 50, 50)).setHref("http://www.foo.com");
Links in a pdf need to specify some rectangle in document coordinates. This rectangle would need to cover the wrapped element(s). Thus, the link element would need to compute its childrens bounding box and accordingly set the link rectangle.
I'd call the object PLExternalLink
because as you mention above there might be also in-document links which share some characteristics (clickable bounding box) but differ in others (need link target inside the same document).
I'd be happy to discuss further.
@martin19 yes indeed, it took some time ;-)
This is the output created by the test file https://github.com/phax/ph-pdf-layout/blob/master/src/test/java/com/helger/pdflayout/element/link/PLExternalLinkTest.java : basic.pdf
I hope it suits your needs. If so, I can build a 6.0.1 release.
The only open issue is imho, if the annotion link should be rendered BEFORE the main content or AFTER the main content. Currently it is done afterwards.
@phax really cool, I didn't realize you were actually working on this already. Thank you!
As you can see on the previous commits, I did some "tries" but never took the time to integrate it. Now it's in :)
Release 6.0.1 is on its way to Maven Central. Happy PDF creation :)
Hi,
Thanks for the library, works like charm. is there a way i can add hyperlink ?
Thanks, Raghvendra