Skip to content

Conversation

@adyry
Copy link
Contributor

@adyry adyry commented Dec 4, 2025

What kind of change does this PR introduce?
Fixes #1591

Checklist:

  • Unit Tests
  • N/A Documentation
  • Update CHANGELOG.md
  • Ready to be merged

PAC Report:
image

}

if (options.structParent && !options.Contents) {
options.Contents = new String('');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just started looking into the validation errors around links, and then I saw your PR, great work!

When I monkey patch your changes into my code, I am still getting this error:
Screenshot 2025-12-04 at 17 04 47

In what instances will the options.Contents be defined here? Because as far as I can see, the linkOptions will either be {} or { structParent: ... } - does this not mean that options.Contents is never defined and options.Contents always set to an empty string.

If I pass the alt text from the doc.struct('Link', {alt: 'alt text here'} used in your example, then this solves the problem, like this:

options.Contents = new String(options.structParent.dictionary.data.Alt || ''); - But I confess that I've only just started looking into this library, so it's still new to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @tr1stan what are you using to check the issue? I've tested on Acrobat PRO (tho I ran out of free trial just today) and on PAC

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I've been using this:
https://pdfix.net/products/pdfix-desktop-lite/

This is in a document I'm rendering, not on your test document though, but I can't see anything that would test differently between the two.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kitchen-sink is a term meaning 'Everything', so kitchen-sink-accessible-tiny doesn't really make sense. I think accessible-links.js (matching the output pdf) is a better name.

@blikblum
Copy link
Member

blikblum commented Dec 5, 2025

There's some code format error

@adyry
Copy link
Contributor Author

adyry commented Dec 11, 2025

There's some code format error

I'm not sure I see them, there're many prettier warnings (most of them not in my files) but eslint passes without an issue 🤔 pushed latest branch update with main

@blikblum
Copy link
Member

According to CI https://github.com/foliojs/pdfkit/actions/runs/20124764259/job/57778504512?pr=1664 , issue is from 2 files this PR touches

Checking formatting...
[warn] lib/mixins/text.js
[warn] tests/unit/text.spec.js

@adyry
Copy link
Contributor Author

adyry commented Dec 11, 2025

I've identified an issue where the links are not terminated properly and are extended to the texts after them, investigating.

@adyry
Copy link
Contributor Author

adyry commented Dec 18, 2025

The fix is here, since _textOptions are inheriting previous properties, they were inheriting link properties as well. Fix removes the properties that shouldn't leak between structure elements. Relevant unit test added.

@adyry adyry requested a review from blikblum December 18, 2025 12:46
@adyry
Copy link
Contributor Author

adyry commented Dec 18, 2025

After the fix even the structure tree issues are addressed in PAC, here's the output for accessible-links.pdf:
image

Comment on lines +103 to +107
delete this._textOptions.link;
delete this._textOptions.goTo;
delete this._textOptions.destination;
delete this._textOptions.underline;
delete this._textOptions.strike;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is necessary delete those?

If possible we should avoid deleting properties

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentioned that in the comment - _textOptions are inheriting previous properties, they were inheriting link properties as well 🤔 Fix removes the properties that shouldn't leak between structure elements

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, these properties shouldn't end up in the _textOptions, but that would require larger refactor

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fair there are other places that follows this pattern.

@blikblum blikblum merged commit 0b01ef4 into foliojs:master Dec 18, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PDF Accessibility Issue (Link annotation is not nested inside a Link structure element)

4 participants