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

Set page reference for new field Widgets #1003

Merged
merged 7 commits into from
Oct 7, 2021

Conversation

Trapfether
Copy link
Contributor

What?

Sets the page reference for field widgets when they are added to a page

Why?

Currently the library does not set the page reference, causing code intended to find the widget's page to fail. Notably, some internal code is also tripped up by this currently as it uses the same methodology.

Ex:
`

const pages = PDFDoc.getPages();
const field = PDFField;
const widget = field.getWidgets()[0];
const pageIndex = pages.findIndex(function(x){return x.ref === widget.P()});
const page = pages[pageIndex];

`

How?

A function has been added to PDFField updateWidgetPageReference that takes the widget annotation and the PDFRef for the page and adds that reference to the widget's dictionary.

This function is called at the end of a fields addToPage function just after adding the widget annotation to the page's internal node

Testing?

I added a unit test for each field that supports an addToPage function. Upon making my changes, I verified that those tests now passed. I also checked the Integration tests to be sure nothing there was messed up. Everything appeared to be in order.

New Dependencies?

No

Screenshots

N/A

Suggested Reading?

Partly

Anything Else?

Linter found a lint rule violation in the src/api/index.ts file. I did not push that as it was unrelated to this fix

Checklist

  • I read CONTRIBUTING.md.
  • I read MAINTAINERSHIP.md#pull-requests.
  • I added/updated unit tests for my changes.
  • I added/updated integration tests for my changes.
  • I ran the integration tests.
  • I tested my changes in Node, Deno, and the browser.
  • I viewed documents produced with my changes in Adobe Acrobat, Foxit Reader, Firefox, and Chrome.
  • I added/updated doc comments for any new/modified public APIs.
  • My changes work for both new and existing PDF files.
  • I ran the linter on my changes.

Copy link
Owner

@Hopding Hopding left a comment

Choose a reason for hiding this comment

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

Looks great overall! Just requested a small refactor.

src/api/form/PDFButton.ts Outdated Show resolved Hide resolved
tests/api/form/PDFCheckBox.spec.ts Show resolved Hide resolved
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.

3 participants