-
-
Notifications
You must be signed in to change notification settings - Fork 198
Add widget page support for placeholder-plain #246
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
base: develop
Are you sure you want to change the base?
Conversation
|
This PR seems like something completely valid. I don't know why it was never reviewed. @sestr any interest in rebasing so we can get this merged? The only possibility I think would be even better is to support the signature being shown on every page. Not part of this PR in any way but an interesting feature to have. It should be doable as long as there are /Widgets on every page all linking to the same /Sig. |
0f20522 to
987cc53
Compare
|
No problem @vbuch, I just did a rebase. Adding a signature to every page is indeed an interesting idea for an additional feature. This could be used, for example, to initial each page of a contract. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for specifying a target page when inserting a signature widget via plainAddPlaceholder.
- Introduces a new
widgetPageparameter in the configuration and JSDoc forplainAddPlaceholder - Updates
plainAddPlaceholderto passwidgetPagethrough togetPageRef - Enhances
getPageRefto accept an optionalpageNumber, split out page references, and validate bounds
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/placeholder-plain/src/plainAddPlaceholder.js | Added widgetPage to JSDoc, function signature defaults, and parameter propagation |
| packages/placeholder-plain/src/getPageRef.js | Extended getPageRef signature, reworked page reference parsing, and added bounds checks |
Comments suppressed due to low confidence (4)
packages/placeholder-plain/src/getPageRef.js:10
- Use lowercase
{number}in JSDoc for consistency with other annotations.
* @param {Number} [pageNumber = 0] Desired page number
packages/placeholder-plain/src/getPageRef.js:22
- [nitpick] Enhance this error message by including the total page count (e.g.,
Page ${pageNumber} out of ${pagesSplit.length} pages) to aid debugging.
throw new SignPdfError(`Failed to get reference of page "${pageNumber}".`, SignPdfError.TYPE_INPUT);
packages/placeholder-plain/src/getPageRef.js:20
- Consider splitting on whitespace with
split(/\s+/)instead of a single space to avoid empty tokens if there are multiple spaces or line breaks.
pages.trim().split(' ').forEach((v, i) => (i % 3 === 0 ? pagesSplit.push([v]) : pagesSplit[pagesSplit.length - 1].push(v)));
packages/placeholder-plain/src/getPageRef.js:19
- [nitpick] You could simplify the chunking logic by iterating over
tokensin steps of 3 (e.g.,for (let i = 0; i < tokens.length; i += 3) pagesSplit.push(tokens.slice(i, i + 3));) for clearer intent.
const pagesSplit = [];
The widget for a signature could only be placed on the first page of a PDF document with the placeholder-plain package. However, it should also be possible to insert the widget on any other page. I made this possible by adding the
widgetPageparameter to the configuration object of theplainAddPlaceholdermethod.