diff --git a/EnvelopeGenerator.Web/wwwroot/js/annotation.js b/EnvelopeGenerator.Web/wwwroot/js/annotation.js index 88071003..e5dcd764 100644 --- a/EnvelopeGenerator.Web/wwwroot/js/annotation.js +++ b/EnvelopeGenerator.Web/wwwroot/js/annotation.js @@ -1,16 +1,87 @@ class Annotation { static createAnnotations(document) { - const annotations = [] - + const signatures = [] document.elements.forEach((element) => { - const [annotation, formField] = Annotation.createAnnotationFromElement(element) - annotations.push(annotation) - annotations.push(formField) + const [annotation, formField] = Annotation.createSignature(element) + signatures.push(annotation) + signatures.push(formField) }) - return annotations + document.elements.forEach((element) => { + const [annotation, formField] = Annotation.createSignature(element) + signatures.push(annotation) + signatures.push(formField) + }) + + return { + signatures: signatures + } } + static createSignature(element) { + const id = PSPDFKit.generateInstantId() + const width = Annotation.inchToPoint(element.width) + const height = Annotation.inchToPoint(element.height) + const top = Annotation.inchToPoint(element.top) - height / 2 + const left = Annotation.inchToPoint(element.left) - width / 2 + const page = element.page - 1 + const annotation = new PSPDFKit.Annotations.WidgetAnnotation({ + id: id, + pageIndex: page, + formFieldName: id, + backgroundColor: PSPDFKit.Color.YELLOW, + blendMode: 'multiply', + boundingBox: new PSPDFKit.Geometry.Rect({ + width, + height, + top, + left, + }), + }) + + const formField = new PSPDFKit.FormFields.SignatureFormField({ + name: id, + annotationIds: PSPDFKit.Immutable.List([annotation.id]), + }) + + return [annotation, formField] + } + + static createTextBox(element) { + const id = PSPDFKit.generateInstantId() + const width = Annotation.inchToPoint(element.width) + const height = Annotation.inchToPoint(element.height) + const top = Annotation.inchToPoint(element.top) - height / 2 + const left = Annotation.inchToPoint(element.left) - width / 2 + const page = element.page - 1 + + //shift + top += height + 10 + + const annotation = new PSPDFKit.Annotations.WidgetAnnotation({ + id: id, + pageIndex: page, + formFieldName: id, + backgroundColor: PSPDFKit.Color.YELLOW, + blendMode: 'multiply', + boundingBox: new PSPDFKit.Geometry.Rect({ + width, + height, + top, + left, + }), + }) + + const formField = new PSPDFKit.FormFields.SignatureFormField({ + name: id, + annotationIds: PSPDFKit.Immutable.List([annotation.id]), + }) + + return [annotation, formField] + } + + static createText + static async getAnnotations(instance) { const array = await Promise.all( Array.from({ length: instance.totalPageCount }).map((_, pageIndex) => @@ -44,35 +115,6 @@ return !!annotation.isSignature || annotation.description == 'FRAME' } - static createAnnotationFromElement(element) { - const id = PSPDFKit.generateInstantId() - const width = Annotation.inchToPoint(element.width) - const height = Annotation.inchToPoint(element.height) - const top = Annotation.inchToPoint(element.top) - height / 2 - const left = Annotation.inchToPoint(element.left) - width / 2 - const page = element.page - 1 - const annotation = new PSPDFKit.Annotations.WidgetAnnotation({ - id: id, - pageIndex: page, - formFieldName: id, - backgroundColor: PSPDFKit.Color.YELLOW, - blendMode: 'multiply', - boundingBox: new PSPDFKit.Geometry.Rect({ - width, - height, - top, - left, - }), - }) - - const formField = new PSPDFKit.FormFields.SignatureFormField({ - name: id, - annotationIds: PSPDFKit.Immutable.List([annotation.id]), - }) - - return [annotation, formField] - } - static createImageAnnotation(boundingBox, pageIndex, imageAttachmentId) { const frameAnnotation = new PSPDFKit.Annotations.ImageAnnotation({ pageIndex: pageIndex, diff --git a/EnvelopeGenerator.Web/wwwroot/js/app.js b/EnvelopeGenerator.Web/wwwroot/js/app.js index 7e560e5f..86fca45e 100644 --- a/EnvelopeGenerator.Web/wwwroot/js/app.js +++ b/EnvelopeGenerator.Web/wwwroot/js/app.js @@ -71,7 +71,7 @@ class App { try { this.signatureCount = this.currentDocument.elements.length const annotations = Annotation.createAnnotations(this.currentDocument) - await this.Instance.create(annotations) + await this.Instance.create(annotations.signatures) const openResponse = await this.Network.openDocument(this.envelopeKey)