This commit is contained in:
Jonathan Jenne
2023-11-13 09:26:48 +01:00
parent 2c936c2629
commit 3874bc742d
14 changed files with 273 additions and 77 deletions

View File

@@ -22,6 +22,7 @@ class App {
this.Instance = null;
this.currentDocument = null;
this.currentReceiver = null;
}
// This function will be called in the ShowEnvelope.razor page
@@ -32,6 +33,9 @@ class App {
console.debug("Loading envelope from database..")
const envelopeObject = await this.Network.getEnvelope(this.envelopeKey);
this.currentDocument = envelopeObject.envelope.documents[0];
this.currentReceiver = envelopeObject.receiver;
console.log(envelopeObject)
// Load the document from the filestore
console.debug("Loading document from filestore")
@@ -47,13 +51,85 @@ class App {
this.Instance = await this.UI.loadPSPDFKit(arrayBuffer, this.container)
this.UI.configurePSPDFKit(this.Instance, this.handleClick.bind(this))
this.Instance.addEventListener("annotations.load", this.handleAnnotationsLoad)
this.Instance.addEventListener("annotations.change", this.handleAnnotationsChange)
this.Instance.addEventListener("annotations.create", this.handleAnnotationsCreate.bind(this))
// Load annotations into PSPDFKit
console.debug("Loading annotations..")
const annotations = this.Annotation.createAnnotations(this.currentDocument)
const createdAnnotations = await this.Instance.create(annotations)
const description = "Umschlag wurde geöffnet"
await this.Network.postHistory(this.envelopeKey, ActionType.Seen, description);
try {
const annotations = this.Annotation.createAnnotations(this.currentDocument)
const createdAnnotations = await this.Instance.create(annotations)
const description = "Umschlag wurde geöffnet"
await this.Network.postHistory(this.envelopeKey, ActionType.Seen, description);
} catch (e) {
console.error(e)
}
}
handleAnnotationsLoad(loadedAnnotations) {
console.log("annotations loaded", loadedAnnotations.toJS());
}
handleAnnotationsChange() {}
async handleAnnotationsCreate(createdAnnotations) {
console.log("annotations created");
console.log(createdAnnotations.toJS())
const annotation = createdAnnotations.toJS()[0];
const isFormField = !!annotation.formFieldName;
const isSignature = !!annotation.isSignature;
console.log("form field", isFormField, "signature", isSignature)
//if (!isSignature) {
// return;
//}
//if (!(isFormField && isSignature)) {
// return;
//}
if (isFormField === false && isSignature === true) {
const left = annotation.boundingBox.left - 25;
const top = annotation.boundingBox.top - 25;
const width = 150;
const height = 75;
console.log(annotation.boundingBox)
const imageUrl = await this.Annotation.createAnnotationFrameBlob(this.currentReceiver.name, width, height);
const request = await fetch(imageUrl);
const blob = await request.blob();
const imageAttachmentId = await this.Instance.createAttachment(blob);
const frameAnnotation = new PSPDFKit.Annotations.ImageAnnotation({
pageIndex: annotation.pageIndex,
isSignature: false,
readOnly: true,
locked: true,
lockedContents: true,
contentType: 'image/png',
imageAttachmentId,
description: 'FRAME',
boundingBox: new PSPDFKit.Geometry.Rect({
left: left,
top: top,
width: width,
height: height,
}),
});
this.Instance.create(frameAnnotation);
}
}
async handleClick(eventType) {