Skip to content

Commit 946b4b3

Browse files
committed
fix: make VisibleElements compatible with envelope
Signed-off-by: Vitor Mattos <[email protected]>
1 parent e916f5c commit 946b4b3

2 files changed

Lines changed: 76 additions & 33 deletions

File tree

src/Components/PdfEditor/PdfEditor.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ export default {
8080
height: signer.element.coordinates.height,
8181
originWidth: signer.element.coordinates.width,
8282
originHeight: signer.element.coordinates.height,
83-
x: signer.element.coordinates.llx,
84-
y: signer.element.coordinates.ury,
83+
x: signer.element.coordinates.left,
84+
y: signer.element.coordinates.top,
8585
}
8686
8787
const docIndex = signer.element.documentIndex !== undefined

src/Components/Request/VisibleElements.vue

Lines changed: 74 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ export default {
225225
226226
for (let i = 0; i < pageCount; i++) {
227227
this.filePagesMap[currentPage + i] = {
228-
uuid: file.uuid,
228+
id: file.id,
229229
fileIndex: index,
230230
startPage: currentPage,
231231
fileName: file.name,
@@ -267,6 +267,15 @@ export default {
267267
this.filesStore.loading = false
268268
}
269269
},
270+
getPageHeightForFile(fileId, page) {
271+
if (this.isEnvelope) {
272+
const fileInfo = this.envelopeFiles.find(f => f.id === fileId)
273+
const metadata = typeof fileInfo?.metadata === 'string' ? JSON.parse(fileInfo.metadata) : fileInfo?.metadata
274+
return metadata?.d?.[page - 1]?.h
275+
}
276+
277+
return this.document?.metadata?.d?.[page - 1]?.h
278+
},
270279
updateSigners(data) {
271280
this.loadedPdfsCount++
272281
@@ -284,27 +293,21 @@ export default {
284293
if (element.signRequestId === signer.signRequestId) {
285294
const object = structuredClone(signer)
286295
287-
if (this.isEnvelope && element.uuid) {
288-
const fileInfo = this.envelopeFiles.find(f => f.uuid === element.uuid)
289-
296+
if (this.isEnvelope && element.fileId) {
297+
const fileInfo = this.envelopeFiles.find(f => f.id === element.fileId)
290298
if (fileInfo) {
291-
for (const [page, info] of Object.entries(this.filePagesMap)) {
292-
if (info.uuid === element.uuid) {
293-
object.element = {
294-
...element,
295-
documentIndex: info.fileIndex,
296-
}
297-
object.element.coordinates.ury = Math.round(data.measurement[element.coordinates.page].height)
298-
- element.coordinates.ury
299-
this.$refs.pdfEditor.addSigner(object)
300-
return
301-
}
299+
const fileIndex = this.envelopeFiles.indexOf(fileInfo)
300+
301+
object.element = {
302+
...element,
303+
documentIndex: fileIndex,
302304
}
305+
306+
this.$refs.pdfEditor.addSigner(object)
307+
return
303308
}
304309
}
305310
306-
element.coordinates.ury = Math.round(data.measurement[element.coordinates.page].height)
307-
- element.coordinates.ury
308311
object.element = element
309312
this.$refs.pdfEditor.addSigner(object)
310313
}
@@ -361,14 +364,29 @@ export default {
361364
const normalizedX = clickX / scale
362365
const normalizedY = clickY / scale
363366
367+
const pageHeight = this.getPageHeightForFile(this.isEnvelope ? this.envelopeFiles[documentIndex]?.id : this.document?.id, pageInDocument)
368+
if (!pageHeight) {
369+
console.error('Missing pageHeight when adding signer', { pageInDocument, documentIndex })
370+
showError(this.$t('libresign', 'Page height metadata not available'))
371+
return
372+
}
373+
const left = normalizedX - this.width / 2
374+
const top = normalizedY - this.height / 2
375+
const llx = left
376+
const ury = pageHeight - top
377+
378+
const coordinates = {
379+
page: pageInDocument,
380+
width: this.width,
381+
height: this.height,
382+
left,
383+
top,
384+
llx,
385+
ury,
386+
}
387+
364388
this.signerSelected.element = {
365-
coordinates: {
366-
page: pageInDocument,
367-
llx: normalizedX - this.width / 2,
368-
ury: normalizedY - this.height / 2,
369-
width: this.width,
370-
height: this.height,
371-
},
389+
coordinates: coordinates,
372390
}
373391
374392
if (this.isEnvelope && documentIndex > 0) {
@@ -428,6 +446,7 @@ export default {
428446
if (!object.signer) return
429447
430448
let globalPageNumber = object.pageNumber
449+
431450
if (this.isEnvelope && docIndex > 0) {
432451
for (const [page, info] of Object.entries(this.filePagesMap)) {
433452
if (info.fileIndex === docIndex) {
@@ -437,23 +456,47 @@ export default {
437456
}
438457
}
439458
440-
const element = {
441-
type: 'signature',
442-
signRequestId: object.signer.signRequestId,
443-
elementId: object.signer.element.elementId,
444-
coordinates: {
459+
let coordinates
460+
if (this.isEnvelope && this.filePagesMap[globalPageNumber]) {
461+
const pageInfo = this.filePagesMap[globalPageNumber]
462+
const pageHeight = this.getPageHeightForFile(pageInfo.id, object.pageNumber)
463+
if (!pageHeight) {
464+
465+
}
466+
467+
const left = Math.floor(object.normalizedCoordinates.llx)
468+
const top = Math.floor(pageHeight - object.normalizedCoordinates.lly)
469+
const width = Math.floor(object.normalizedCoordinates.width)
470+
const height = Math.floor(object.normalizedCoordinates.height)
471+
472+
coordinates = {
473+
page: globalPageNumber,
474+
width,
475+
height,
476+
left,
477+
top,
478+
}
479+
} else {
480+
coordinates = {
445481
page: globalPageNumber,
446482
width: object.normalizedCoordinates.width,
447483
height: object.normalizedCoordinates.height,
448484
llx: object.normalizedCoordinates.llx,
449485
lly: object.normalizedCoordinates.lly,
450486
ury: object.normalizedCoordinates.ury,
451487
urx: object.normalizedCoordinates.urx,
452-
},
488+
}
489+
}
490+
491+
const element = {
492+
type: 'signature',
493+
signRequestId: object.signer.signRequestId,
494+
elementId: object.signer.element.elementId,
495+
coordinates: coordinates,
453496
}
454497
455498
if (this.isEnvelope && this.filePagesMap[globalPageNumber]) {
456-
element.uuid = this.filePagesMap[globalPageNumber].uuid
499+
element.fileId = this.filePagesMap[globalPageNumber].id
457500
element.coordinates.page = globalPageNumber - this.filePagesMap[globalPageNumber].startPage + 1
458501
}
459502

0 commit comments

Comments
 (0)