fix(annotations): correct signature frame mapping by filtering by pageIndex

- Updated `mapSignature` to filter signature annotations by `pageIndex` when finding nearest elements.
- Ensures correct association of frames and signature data for each page.
- Prevents errors caused by cross-page annotation references.
This commit is contained in:
tekh 2025-10-28 12:59:49 +01:00
parent 5e74de0ce7
commit 038ac2aed0
3 changed files with 8 additions and 4 deletions

View File

@ -331,7 +331,9 @@ function mapSignature(iJSON) {
// frames // frames
...iJSON.annotations.filter(annot => annot.description === 'FRAME').map((annot) => { ...iJSON.annotations.filter(annot => annot.description === 'FRAME').map((annot) => {
const preElement = findNearest(annot, e => e.bbox[0], e => e.bbox[1], ...iJSON.annotations.filter(field => field.id.includes("signature"))); const preElement = findNearest(annot, e => e.bbox[0], e => e.bbox[1], iJSON.annotations.filter(
field => field.id.includes("signature") && field.pageIndex === annot.pageIndex
));
const idPartsOfPre = preElement.id.split('#'); const idPartsOfPre = preElement.id.split('#');
return { return {
elementId: Number(idPartsOfPre[2]), elementId: Number(idPartsOfPre[2]),
@ -343,7 +345,9 @@ function mapSignature(iJSON) {
// signatures // signatures
...iJSON.annotations.filter(annot => annot.isSignature).map(annot => { ...iJSON.annotations.filter(annot => annot.isSignature).map(annot => {
const preElement = findNearest(annot, e => e.bbox[0], e => e.bbox[1], ...iJSON.annotations.filter(field => field.id.includes("signature"))); const preElement = findNearest(annot, e => e.bbox[0], e => e.bbox[1], iJSON.annotations.filter(
field => field.id.includes("signature") && field.pageIndex === annot.pageIndex
));
const idPartsOfPre = preElement.id.split('#'); const idPartsOfPre = preElement.id.split('#');
let value; let value;

View File

@ -14,7 +14,7 @@ function detailedCurrentDate() {
}).format(); }).format();
} }
function findNearest(origin, getX, getY, ...dests) { function findNearest(origin, getX, getY, dests) {
const distanceToOrigin = (point) => Math.sqrt((getX(origin) - getX(point))**2 + (getY(origin) - getY(point))**2); const distanceToOrigin = (point) => Math.sqrt((getX(origin) - getX(point))**2 + (getY(origin) - getY(point))**2);
return dests.reduce( return dests.reduce(
(nearest, dest) => { (nearest, dest) => {

View File

@ -1 +1 @@
function detailedCurrentDate(){return new Intl.DateTimeFormat("de-DE",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:"shortOffset"}).format()}function findNearest(n,t,i,...r){const u=r=>Math.sqrt((t(n)-t(r))**2+(i(n)-i(r))**2);return r.reduce((n,t)=>{const i=u(t);return i<n.dist?{dist:i,dest:t}:n},{dist:Infinity,dest:null}).dest}const B64ToBuff=n=>new Uint8Array(Array.from(atob(n),n=>n.charCodeAt(0))).buffer,getLocaleDateString=()=>(new Date).toLocaleDateString("de-DE"); function detailedCurrentDate(){return new Intl.DateTimeFormat("de-DE",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:"shortOffset"}).format()}function findNearest(n,t,i,r){const u=r=>Math.sqrt((t(n)-t(r))**2+(i(n)-i(r))**2);return r.reduce((n,t)=>{const i=u(t);return i<n.dist?{dist:i,dest:t}:n},{dist:Infinity,dest:null}).dest}const B64ToBuff=n=>new Uint8Array(Array.from(atob(n),n=>n.charCodeAt(0))).buffer,getLocaleDateString=()=>(new Date).toLocaleDateString("de-DE");