Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for links (<a> elements) #18

Closed
alafr opened this issue Nov 26, 2016 · 6 comments
Closed

Add support for links (<a> elements) #18

alafr opened this issue Nov 26, 2016 · 6 comments
Labels

Comments

@alafr
Copy link
Owner

alafr commented Nov 26, 2016

I think it won't be possible because in PDFKit (and in PDF 1.3) links are only supported for a few basic shapes. And even with the polygon links supported it would be difficult to implement.
I keep this issue open because the children of the <a> tag must be rendered even without the link.

@alafr alafr added the wontfix label Dec 3, 2016
@alafr
Copy link
Owner Author

alafr commented Jun 7, 2017

Children of <a> elements are rendered since commit 84064ba

@alafr alafr closed this as completed Jun 8, 2017
@peonmodel
Copy link

peonmodel commented Dec 14, 2017

could <a> be honored if the children are just text elements? i am just trying to make some simple text into a link

@alafr
Copy link
Owner Author

alafr commented Dec 14, 2017

Yes it can probably be done. I see a few options:

  1. Add link support for basic rectangular texts (difficulty: how to determine if a text is rectangular)
  2. Add complete link support for text, with a link for each character (problem: PDFKit has no support for rotated links and text can be rotated by many different ways)
  3. Add the link to the whole bounding box of the element (problem: the link will also be active outside of the non-rectangular elements)
    I think the option 3 is reasonably easy to implement but since in can have undesired results it should be offered as an option. I don't have time to try this right now but if you want you can send a pull request.

@alafr alafr reopened this Dec 14, 2017
@peonmodel
Copy link

peonmodel commented Dec 15, 2017

i investigated having a link in pdf with arbitrary shape and rotation, it doesnt seem possible, (it doesnt seemed to be a PDFKit limitation, rather a pdf format issue)
https://superuser.com/questions/1277302/can-a-link-rectangle-in-pdf-be-rotated

the strategy used by chrome is simply create an oversized link rectangle that covers the entire object (which is similar to your option 3)

  1. if a text has no matrix transformation and is not a textpath, can it be assumed to be rectangular?

i shall try implement option 3

a related bug

commit 84064ba seems to only work for top level <a>
<a> that are children of text elements are completely ignored, <a> children are ignored

@alafr alafr added bug and removed wontfix labels Dec 15, 2017
@alafr
Copy link
Owner Author

alafr commented Dec 15, 2017

It would be good to do it like chrome, I had never noticed that it makes oversized links when printing as PDF. It's actually quite rare to have non-rectangular links.
I almost fixed the related bug, there is still an issue when a <textPath> is a direct child of the <a> element.

@alafr alafr added feature and removed bug labels Dec 15, 2017
@alafr
Copy link
Owner Author

alafr commented Jan 3, 2018

Support for links added in version 0.1.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants