25-09-2023

This commit is contained in:
Jonathan Jenne
2023-09-25 14:28:12 +02:00
parent 0533ccef63
commit 8c5f2f3d38
12 changed files with 230 additions and 96 deletions

View File

@@ -39,23 +39,18 @@ var Rect = PSPDFKit.Geometry.Rect;
var SignatureFormField = PSPDFKit.FormFields.SignatureFormField;
var _a = PSPDFKit.ElectronicSignatureCreationMode, DRAW = _a.DRAW, TYPE = _a.TYPE;
var DISABLED = PSPDFKit.AutoSaveMode.DISABLED;
var Settings = /** @class */ (function () {
function Settings() {
}
Settings.allowedToolbarItems = [
"sidebar-thumbnails",
"sidebar-document-ouline",
"sidebar-bookmarks",
"pager",
"pan",
"zoom-out",
"zoom-in",
"zoom-mode",
"spacer",
"search"
];
return Settings;
}());
var allowedToolbarItems = [
"sidebar-thumbnails",
"sidebar-document-ouline",
"sidebar-bookmarks",
"pager",
"pan",
"zoom-out",
"zoom-in",
"zoom-mode",
"spacer",
"search"
];
var App = /** @class */ (function () {
function App() {
}
@@ -63,33 +58,52 @@ var App = /** @class */ (function () {
// and will trigger loading of the Editor Interface
App.loadPDFFromUrl = function (container, envelopeKey) {
return __awaiter(this, void 0, void 0, function () {
var arrayBuffer, envelopeObject, _a, id, annotation, formField, createdAnnotation;
var envelopeObject, document, arrayBuffer, e_1, _a, annotations, createdAnnotation;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
console.debug("Loading PSPDFKit..");
return [4 /*yield*/, App.loadDocument("/api/download/".concat(envelopeKey))];
case 1:
arrayBuffer = _b.sent();
return [4 /*yield*/, App.loadData("/api/get-data/".concat(envelopeKey))];
case 2:
case 1:
envelopeObject = _b.sent();
document = envelopeObject.envelope.documents[0];
_b.label = 2;
case 2:
_b.trys.push([2, 4, , 5]);
return [4 /*yield*/, App.loadDocument("/api/download/".concat(envelopeKey, "?id=").concat(document.id))];
case 3:
arrayBuffer = _b.sent();
return [3 /*break*/, 5];
case 4:
e_1 = _b.sent();
console.error(e_1);
return [3 /*break*/, 5];
case 5:
_a = App;
return [4 /*yield*/, App.loadPSPDFKit(arrayBuffer, container)];
case 3:
case 6:
_a.Instance = _b.sent();
App.configurePSPDFKit(this.Instance);
console.debug(envelopeObject.envelope.id);
console.debug(envelopeObject.envelope);
console.debug("PSPDFKit configured!");
id = PSPDFKit.generateInstantId();
annotation = App.createSignatureAnnotation(id, 150, 50, 50, 50, 0);
formField = new SignatureFormField({
name: id,
annotationIds: List([annotation.id])
annotations = [];
document.elements.forEach(function (element) {
console.log("Loading element");
console.debug("Page", element.page);
console.debug("Width / Height", element.width, element.height);
console.debug("Top / Left", element.top, element.left);
var id = PSPDFKit.generateInstantId();
var annotation = App.createSignatureAnnotation(id, element.width, element.height, element.top, element.left, element.page);
var formField = new SignatureFormField({
name: id,
annotationIds: List([annotation.id])
});
annotations.push(annotation);
annotations.push(formField);
console.debug("Annotation created.");
});
console.debug("Annotation created.");
return [4 /*yield*/, App.Instance.create([annotation, formField])];
case 4:
return [4 /*yield*/, App.Instance.create(annotations)];
case 7:
createdAnnotation = (_b.sent())[0];
console.debug(createdAnnotation);
return [2 /*return*/];
@@ -137,12 +151,12 @@ var App = /** @class */ (function () {
console.log("annotations created", createdAnnotations.toJS());
});
var filteredItems = instance.toolbarItems
.filter(function (item) { return Settings.allowedToolbarItems.includes(item.type); });
.filter(function (item) { return allowedToolbarItems.includes(item.type); });
var customItems = [
{
type: "custom",
id: "button-finish",
title: "Abschließen",
title: "Abschlie<EFBFBD>en",
icon: "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"20\" height=\"20\" fill=\"currentColor\" class=\"bi bi-check2-circle\" viewBox=\"0 0 16 16\">\n <path d=\"M2.5 8a5.5 5.5 0 0 1 8.25-4.764.5.5 0 0 0 .5-.866A6.5 6.5 0 1 0 14.5 8a.5.5 0 0 0-1 0 5.5 5.5 0 1 1-11 0z\"/>\n <path d=\"M15.354 3.354a.5.5 0 0 0-.708-.708L8 9.293 5.354 6.646a.5.5 0 1 0-.708.708l3 3a.5.5 0 0 0 .708 0l7-7z\" />\n </svg>",
onPress: this.handleFinish
}
@@ -201,17 +215,12 @@ var App = /** @class */ (function () {
});
});
};
App.createSignatureAnnotation = function (id, x, y, top, left, pageIndex) {
App.createSignatureAnnotation = function (id, width, height, top, left, pageIndex) {
var annotation = new PSPDFKit.Annotations.WidgetAnnotation({
id: id,
pageIndex: pageIndex,
formFieldName: id,
boundingBox: new Rect({
width: x,
height: y,
top: top,
left: left
})
boundingBox: new Rect({ width: width, height: height, top: top, left: left })
});
return annotation;
};