Skip to content

Conversation

@sestr
Copy link

@sestr sestr commented Apr 2, 2024

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 widgetPage parameter to the configuration object of the plainAddPlaceholder method.

@coveralls
Copy link

Coverage Status

coverage: 99.319% (-0.3%) from 99.636%
when pulling 0f20522 on sestr:feature/widget-page
into 4a6a2a4 on vbuch:develop.

@vbuch
Copy link
Owner

vbuch commented Apr 7, 2025

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.

@sestr sestr force-pushed the feature/widget-page branch from 0f20522 to 987cc53 Compare April 10, 2025 15:22
@sestr
Copy link
Author

sestr commented Apr 10, 2025

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.

@coveralls
Copy link

Coverage Status

coverage: 99.47% (-0.5%) from 100.0%
when pulling 987cc53 on sestr:feature/widget-page
into f54ca67 on vbuch:develop.

@vbuch vbuch requested a review from Copilot June 8, 2025 07:52
Copy link

Copilot AI left a 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 widgetPage parameter in the configuration and JSDoc for plainAddPlaceholder
  • Updates plainAddPlaceholder to pass widgetPage through to getPageRef
  • Enhances getPageRef to accept an optional pageNumber, 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 tokens in 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 = [];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants