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

@ -26,9 +26,7 @@
Public Shared Function GetEnvelopeURL(pHost As String, pEnvelopeUuid As String, pReceiverSignature As String) As String Public Shared Function GetEnvelopeURL(pHost As String, pEnvelopeUuid As String, pReceiverSignature As String) As String
Dim oEnvelopeUserReference As String = EncodeEnvelopeReceiverId(pEnvelopeUuid, pReceiverSignature) Dim oEnvelopeUserReference As String = EncodeEnvelopeReceiverId(pEnvelopeUuid, pReceiverSignature)
Dim oURL As String = String.Format("{0}/EnvelopeKey/{1}", pHost.Trim(), oEnvelopeUserReference)
Dim oURL As String = ""
oURL = String.Format("{0}/EnvelopeKey/{1}", pHost.Trim(), oEnvelopeUserReference)
Return oURL Return oURL
End Function End Function

View File

@ -1,5 +1,7 @@
using EnvelopeGenerator.Common; using EnvelopeGenerator.Common;
using EnvelopeGenerator.Common.My.Resources;
using EnvelopeGenerator.Web.Services; using EnvelopeGenerator.Web.Services;
using Microsoft.Extensions.Primitives;
namespace EnvelopeGenerator.Web.Handler namespace EnvelopeGenerator.Web.Handler
{ {
@ -7,6 +9,7 @@ namespace EnvelopeGenerator.Web.Handler
{ {
public async static Task<IResult> HandleFile(HttpContext ctx, DatabaseService database, LoggingService logging) public async static Task<IResult> HandleFile(HttpContext ctx, DatabaseService database, LoggingService logging)
{ {
var logger = logging.LogConfig.GetLogger("FileHandler"); var logger = logging.LogConfig.GetLogger("FileHandler");
string envelopeKey = (string)ctx.Request.RouteValues["envelopeKey"]; string envelopeKey = (string)ctx.Request.RouteValues["envelopeKey"];
@ -22,12 +25,52 @@ namespace EnvelopeGenerator.Web.Handler
logger.Info("Contains [{0}] documents", envelope.Documents.Count); logger.Info("Contains [{0}] documents", envelope.Documents.Count);
logger.Info("Contains [{0}] receivers", envelope.Receivers.Count); logger.Info("Contains [{0}] receivers", envelope.Receivers.Count);
int documentId = getDocumentIndex(ctx);
var document = getDocument(envelope, documentId);
try
{
var bytes = await File.ReadAllBytesAsync(document.Filepath);
logger.Info("Serving file, size: [{0}]", bytes.Length);
return Results.File(bytes);
}
catch (Exception e)
{
logger.Error(e);
return Results.Problem();
}
}
private static int getDocumentIndex(HttpContext ctx)
{
int documentId = 0;
StringValues documentIndexString;
if (ctx.Request.Query.TryGetValue("index", out documentIndexString))
{
int.TryParse(documentIndexString.First(), out documentId);
}
return documentId;
}
private static EnvelopeDocument getDocument(Common.Envelope envelope, int documentId)
{
var document = envelope.Documents.First(); var document = envelope.Documents.First();
var bytes = await File.ReadAllBytesAsync(document.Filepath); if (documentId > 0)
logger.Info("Serving file, size: [{0}]", bytes.Length); {
var documentById = envelope.Documents.
Where(d => d.Id == documentId).
FirstOrDefault();
return Results.File(bytes); if (documentById != null)
{
document = documentById;
}
}
return document;
} }
public static Task<IResult> HandleGetData(HttpContext ctx, DatabaseService database, LoggingService logging) public static Task<IResult> HandleGetData(HttpContext ctx, DatabaseService database, LoggingService logging)

View File

@ -1,5 +1,6 @@
import PSPDFKitType, { AnnotationsUnion } from "./index"; import PSPDFKitType, { AnnotationsUnion } from "./index";
import { Instance, WidgetAnnotation, ToolbarItem } from "./index"; import { Instance, WidgetAnnotation, ToolbarItem } from "./index";
import { EnvelopeResponse, Envelope, User, Element, Document } from "./interfaces";
declare const PSPDFKit: typeof PSPDFKitType declare const PSPDFKit: typeof PSPDFKitType
@ -9,63 +10,67 @@ const { SignatureFormField } = PSPDFKit.FormFields;
const { DRAW, TYPE } = PSPDFKit.ElectronicSignatureCreationMode; const { DRAW, TYPE } = PSPDFKit.ElectronicSignatureCreationMode;
const { DISABLED } = PSPDFKit.AutoSaveMode; const { DISABLED } = PSPDFKit.AutoSaveMode;
interface EnvelopeResponse { const allowedToolbarItems: string[] = [
receiverId: number; "sidebar-thumbnails",
envelope: Envelope; "sidebar-document-ouline",
} "sidebar-bookmarks",
"pager",
interface Envelope { "pan",
id: number; "zoom-out",
userId: number; "zoom-in",
title: string; "zoom-mode",
contractType: number; "spacer",
status: number; "search"
uuid: string; ]
}
class Settings {
public static allowedToolbarItems: string[] = [
"sidebar-thumbnails",
"sidebar-document-ouline",
"sidebar-bookmarks",
"pager",
"pan",
"zoom-out",
"zoom-in",
"zoom-mode",
"spacer",
"search"
]
}
export class App { export class App {
public static Instance: Instance; public static Instance: Instance;
public static currentDocument
// This function will be called in the ShowEnvelope.razor page // This function will be called in the ShowEnvelope.razor page
// and will trigger loading of the Editor Interface // and will trigger loading of the Editor Interface
public static async loadPDFFromUrl (container: string, envelopeKey: string) { public static async loadPDFFromUrl (container: string, envelopeKey: string) {
console.debug("Loading PSPDFKit.."); console.debug("Loading PSPDFKit..");
const arrayBuffer = await App.loadDocument(`/api/download/${envelopeKey}`);
const envelopeObject: EnvelopeResponse = await App.loadData(`/api/get-data/${envelopeKey}`); const envelopeObject: EnvelopeResponse = await App.loadData(`/api/get-data/${envelopeKey}`);
const document: Document = envelopeObject.envelope.documents[0];
let arrayBuffer
try {
arrayBuffer = await App.loadDocument(`/api/download/${envelopeKey}?id=${document.id}`);
} catch (e) {
console.error(e)
}
App.Instance = await App.loadPSPDFKit(arrayBuffer, container) App.Instance = await App.loadPSPDFKit(arrayBuffer, container)
App.configurePSPDFKit(this.Instance) App.configurePSPDFKit(this.Instance)
console.debug(envelopeObject.envelope.id); console.debug(envelopeObject.envelope);
console.debug("PSPDFKit configured!"); console.debug("PSPDFKit configured!");
const id = PSPDFKit.generateInstantId() const annotations: any[] = [];
const annotation: WidgetAnnotation = App.createSignatureAnnotation(id, 150, 50, 50, 50, 0)
const formField = new SignatureFormField({ document.elements.forEach(function (element: Element) {
name: id, console.log("Loading element")
annotationIds: List([annotation.id]) console.debug("Page", element.page)
console.debug("Width / Height", element.width, element.height)
console.debug("Top / Left", element.top, element.left)
const id = PSPDFKit.generateInstantId()
const annotation: WidgetAnnotation = App.createSignatureAnnotation(id, element.width, element.height, element.top, element.left, element.page)
const formField = new SignatureFormField({
name: id,
annotationIds: List([annotation.id])
})
annotations.push(annotation);
annotations.push(formField);
console.debug("Annotation created.")
}) })
console.debug("Annotation created.") const [createdAnnotation] = await App.Instance.create(annotations)
const [createdAnnotation] = await App.Instance.create([annotation, formField])
console.debug(createdAnnotation) console.debug(createdAnnotation)
} }
@ -117,7 +122,8 @@ export class App {
}) })
const filteredItems: Array<ToolbarItem> = instance.toolbarItems const filteredItems: Array<ToolbarItem> = instance.toolbarItems
.filter((item) => Settings.allowedToolbarItems.includes(item.type)) .filter((item) => allowedToolbarItems.includes(item.type))
const customItems: ToolbarItem[] = [ const customItems: ToolbarItem[] = [
{ {
@ -171,17 +177,12 @@ export class App {
} }
private static createSignatureAnnotation(id: string, x: number, y: number, top: number, left: number, pageIndex: number): WidgetAnnotation { private static createSignatureAnnotation(id: string, width: number, height: number, top: number, left: number, pageIndex: number): WidgetAnnotation {
const annotation = new PSPDFKit.Annotations.WidgetAnnotation({ const annotation = new PSPDFKit.Annotations.WidgetAnnotation({
id: id, id: id,
pageIndex: pageIndex, pageIndex: pageIndex,
formFieldName: id, formFieldName: id,
boundingBox: new Rect({ boundingBox: new Rect({ width, height, top, left })
width: x,
height: y,
top: top,
left: left
})
}) })
return annotation return annotation

View File

@ -0,0 +1,47 @@
interface EnvelopeResponse {
receiverId: number;
envelope: Envelope;
}
interface Envelope {
id: number;
userId: number;
title: string;
status: number;
statusTranslated: string;
contractType: number;
contractTypeTranslated: string;
subject: string;
uuid: string;
user: User;
documents: Document[];
}
interface Document {
id: number;
filepath: string;
filename: string;
elements: Element[];
}
interface Element {
id: number;
left: number;
top: number;
width: number;
height: number;
page: number;
readOnly: boolean;
}
interface User {
id: number;
email: string;
name: string;
prename: string;
username: string;
language: string;
fullName: string;
}
export { EnvelopeResponse, Envelope, Document, Element, User }

View File

@ -9,7 +9,7 @@
"moduleResolution": "Classic", "moduleResolution": "Classic",
"sourceMap": true, "sourceMap": true,
"target": "es5", "target": "es5",
"lib": ["ES2016", "DOM"] "lib": [ "ES2016", "DOM" ]
}, },
"include": [ "include": [
"Scripts/**/*.ts" "Scripts/**/*.ts"

View File

@ -0,0 +1,20 @@
{
"compileOnSave": true,
"compilerOptions": {
"noEmitOnError": true,
"noImplicitAny": false,
"outDir": "wwwroot/js",
"removeComments": false,
"module": "ES2015",
"moduleResolution": "Classic",
"sourceMap": true,
"target": "es5",
"lib": ["ES2016", "DOM"]
},
"include": [
"Scripts/**/*.ts"
],
"exclude": [
"node_modules"
]
}

View File

@ -39,23 +39,18 @@ var Rect = PSPDFKit.Geometry.Rect;
var SignatureFormField = PSPDFKit.FormFields.SignatureFormField; var SignatureFormField = PSPDFKit.FormFields.SignatureFormField;
var _a = PSPDFKit.ElectronicSignatureCreationMode, DRAW = _a.DRAW, TYPE = _a.TYPE; var _a = PSPDFKit.ElectronicSignatureCreationMode, DRAW = _a.DRAW, TYPE = _a.TYPE;
var DISABLED = PSPDFKit.AutoSaveMode.DISABLED; var DISABLED = PSPDFKit.AutoSaveMode.DISABLED;
var Settings = /** @class */ (function () { var allowedToolbarItems = [
function Settings() { "sidebar-thumbnails",
} "sidebar-document-ouline",
Settings.allowedToolbarItems = [ "sidebar-bookmarks",
"sidebar-thumbnails", "pager",
"sidebar-document-ouline", "pan",
"sidebar-bookmarks", "zoom-out",
"pager", "zoom-in",
"pan", "zoom-mode",
"zoom-out", "spacer",
"zoom-in", "search"
"zoom-mode", ];
"spacer",
"search"
];
return Settings;
}());
var App = /** @class */ (function () { var App = /** @class */ (function () {
function App() { function App() {
} }
@ -63,33 +58,52 @@ var App = /** @class */ (function () {
// and will trigger loading of the Editor Interface // and will trigger loading of the Editor Interface
App.loadPDFFromUrl = function (container, envelopeKey) { App.loadPDFFromUrl = function (container, envelopeKey) {
return __awaiter(this, void 0, void 0, function () { 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) { return __generator(this, function (_b) {
switch (_b.label) { switch (_b.label) {
case 0: case 0:
console.debug("Loading PSPDFKit.."); 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))]; return [4 /*yield*/, App.loadData("/api/get-data/".concat(envelopeKey))];
case 2: case 1:
envelopeObject = _b.sent(); 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; _a = App;
return [4 /*yield*/, App.loadPSPDFKit(arrayBuffer, container)]; return [4 /*yield*/, App.loadPSPDFKit(arrayBuffer, container)];
case 3: case 6:
_a.Instance = _b.sent(); _a.Instance = _b.sent();
App.configurePSPDFKit(this.Instance); App.configurePSPDFKit(this.Instance);
console.debug(envelopeObject.envelope.id); console.debug(envelopeObject.envelope);
console.debug("PSPDFKit configured!"); console.debug("PSPDFKit configured!");
id = PSPDFKit.generateInstantId(); annotations = [];
annotation = App.createSignatureAnnotation(id, 150, 50, 50, 50, 0); document.elements.forEach(function (element) {
formField = new SignatureFormField({ console.log("Loading element");
name: id, console.debug("Page", element.page);
annotationIds: List([annotation.id]) 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(annotations)];
return [4 /*yield*/, App.Instance.create([annotation, formField])]; case 7:
case 4:
createdAnnotation = (_b.sent())[0]; createdAnnotation = (_b.sent())[0];
console.debug(createdAnnotation); console.debug(createdAnnotation);
return [2 /*return*/]; return [2 /*return*/];
@ -137,12 +151,12 @@ var App = /** @class */ (function () {
console.log("annotations created", createdAnnotations.toJS()); console.log("annotations created", createdAnnotations.toJS());
}); });
var filteredItems = instance.toolbarItems var filteredItems = instance.toolbarItems
.filter(function (item) { return Settings.allowedToolbarItems.includes(item.type); }); .filter(function (item) { return allowedToolbarItems.includes(item.type); });
var customItems = [ var customItems = [
{ {
type: "custom", type: "custom",
id: "button-finish", 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>", 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 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({ var annotation = new PSPDFKit.Annotations.WidgetAnnotation({
id: id, id: id,
pageIndex: pageIndex, pageIndex: pageIndex,
formFieldName: id, formFieldName: id,
boundingBox: new Rect({ boundingBox: new Rect({ width: width, height: height, top: top, left: left })
width: x,
height: y,
top: top,
left: left
})
}); });
return annotation; return annotation;
}; };

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=interfaces.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../Scripts/interfaces.ts"],"names":[],"mappings":""}

View File

@ -1 +1,14 @@
const allowedToolbarItems = [
"sidebar-thumbnails",
"sidebar-document-ouline",
"sidebar-bookmarks",
"pager",
"pan",
"zoom-out",
"zoom-in",
"zoom-mode",
"spacer",
"search"
];
export { allowedToolbarItems };
//# sourceMappingURL=settings.js.map //# sourceMappingURL=settings.js.map

View File

@ -1 +1 @@
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../Scripts/settings.ts"],"names":[],"mappings":""} {"version":3,"file":"settings.js","sourceRoot":"","sources":["../../Scripts/settings.ts"],"names":[],"mappings":"AAAA,MAAM,mBAAmB,GAAa;IAClC,oBAAoB;IACpB,yBAAyB;IACzB,mBAAmB;IACnB,OAAO;IACP,KAAK;IACL,UAAU;IACV,SAAS;IACT,WAAW;IACX,QAAQ;IACR,QAAQ;CACX,CAAA;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAA"}