From d8fdedcb1029832e4d80be81383aaa993a72011e Mon Sep 17 00:00:00 2001 From: Andrey Safonov Date: Mon, 7 Dec 2020 17:07:50 -0800 Subject: [PATCH 1/3] Added date picker to the app --- .../PrepareDocument/PrepareDocument.js | 46 ++++++++++++++----- src/components/SignDocument/SignDocument.js | 1 - 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/components/PrepareDocument/PrepareDocument.js b/src/components/PrepareDocument/PrepareDocument.js index 9afa583..172d36f 100644 --- a/src/components/PrepareDocument/PrepareDocument.js +++ b/src/components/PrepareDocument/PrepareDocument.js @@ -88,15 +88,6 @@ const PrepareDocument = () => { let field; if (typeof annot.custom !== 'undefined') { - // set flags - const flags = new Annotations.WidgetFlags(); - if (annot.custom.flag.readOnly) { - flags.set('ReadOnly', true); - } - if (annot.custom.flag.multiline) { - flags.set('Multiline', true); - } - // create a form field based on the type of annotation if (annot.custom.type === 'TEXT') { field = new Annotations.Forms.Field( @@ -104,7 +95,6 @@ const PrepareDocument = () => { { type: 'Tx', value: annot.custom.value, - flags, }, ); inputAnnot = new Annotations.TextWidgetAnnotation(field); @@ -113,7 +103,6 @@ const PrepareDocument = () => { annot.getContents() + Date.now() + index, { type: 'Sig', - flags, }, ); inputAnnot = new Annotations.SignatureWidgetAnnotation(field, { @@ -131,6 +120,27 @@ const PrepareDocument = () => { }, }, }); + } else if (annot.custom.type === 'DATE') { + field = new Annotations.Forms.Field( + annot.getContents() + Date.now() + index, + { + type: 'Tx', + value: 'm-d-yyyy', + // Actions need to be added for DatePickerWidgetAnnotation to recognize this field. + actions: { + F: [ + { + name: 'JavaScript', + // You can customize the date format here between the two double-quotation marks + // or leave this blank to use the default format + javascript: '"m-d-yyyy"', + }, + ], + }, + }, + ); + + inputAnnot = new Annotations.DatePickerWidgetAnnotation(field); } else { // exit early for other annotations annotManager.deleteAnnotation(annot, false, true); // prevent duplicates when importing xfdf @@ -365,6 +375,20 @@ const PrepareDocument = () => { /> + +
dragStart(e)} + onDragEnd={e => dragEnd(e, 'DATE')} + > +
+
diff --git a/src/components/SignDocument/SignDocument.js b/src/components/SignDocument/SignDocument.js index 9025375..9326c62 100644 --- a/src/components/SignDocument/SignDocument.js +++ b/src/components/SignDocument/SignDocument.js @@ -57,7 +57,6 @@ const SignDocument = () => { return { 'background-color': '#a5c7ff', color: 'white', - 'font-size': '20px', }; } else if (widget instanceof Annotations.SignatureWidgetAnnotation) { return { From e701c57ba6599c381e117d8089b5537e096f8964 Mon Sep 17 00:00:00 2001 From: Andrey Safonov Date: Tue, 8 Dec 2020 11:47:44 -0800 Subject: [PATCH 2/3] Added await to functions that return promise - Added await to functions returning promise - Added additional flags to ensure widgets and flags get picked up --- src/components/PrepareDocument/PrepareDocument.js | 6 +++--- src/components/SignDocument/SignDocument.js | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/components/PrepareDocument/PrepareDocument.js b/src/components/PrepareDocument/PrepareDocument.js index 172d36f..90a22d7 100644 --- a/src/components/PrepareDocument/PrepareDocument.js +++ b/src/components/PrepareDocument/PrepareDocument.js @@ -151,7 +151,7 @@ const PrepareDocument = () => { return; } - // set flag and position + // set position inputAnnot.PageNumber = annot.getPageNumber(); inputAnnot.X = annot.getX(); inputAnnot.Y = annot.getY(); @@ -188,7 +188,7 @@ const PrepareDocument = () => { annotManager.deleteAnnotations(annotsToDelete, null, true); // refresh viewer - annotManager.drawAnnotationsFromList(annotsToDraw); + await annotManager.drawAnnotationsFromList(annotsToDraw); await uploadForSigning(); }; @@ -253,7 +253,7 @@ const PrepareDocument = () => { const docRef = storageRef.child(referenceString); const { docViewer, annotManager } = instance; const doc = docViewer.getDocument(); - const xfdfString = await annotManager.exportAnnotations(); + const xfdfString = await annotManager.exportAnnotations({ widgets: true, fields: true }); const data = await doc.getFileData({ xfdfString }); const arr = new Uint8Array(data); const blob = new Blob([arr], { type: 'application/pdf' }); diff --git a/src/components/SignDocument/SignDocument.js b/src/components/SignDocument/SignDocument.js index 9326c62..6e9885d 100644 --- a/src/components/SignDocument/SignDocument.js +++ b/src/components/SignDocument/SignDocument.js @@ -49,7 +49,6 @@ const SignDocument = () => { // load document const storageRef = storage.ref(); const URL = await storageRef.child(docRef).getDownloadURL(); - console.log(URL); docViewer.loadDocument(URL); const normalStyles = (widget) => { From 3c623c97d0b678477199b1845e38f836f3f20eba Mon Sep 17 00:00:00 2001 From: Andrey Safonov Date: Tue, 8 Dec 2020 12:42:51 -0800 Subject: [PATCH 3/3] Added proper action for formattin date --- src/components/PrepareDocument/PrepareDocument.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/PrepareDocument/PrepareDocument.js b/src/components/PrepareDocument/PrepareDocument.js index 90a22d7..bc77f88 100644 --- a/src/components/PrepareDocument/PrepareDocument.js +++ b/src/components/PrepareDocument/PrepareDocument.js @@ -133,7 +133,15 @@ const PrepareDocument = () => { name: 'JavaScript', // You can customize the date format here between the two double-quotation marks // or leave this blank to use the default format - javascript: '"m-d-yyyy"', + javascript: 'AFDate_FormatEx("mmm d, yyyy");', + }, + ], + K: [ + { + name: 'JavaScript', + // You can customize the date format here between the two double-quotation marks + // or leave this blank to use the default format + javascript: 'AFDate_FormatEx("mmm d, yyyy");', }, ], },