mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
signature: manage multi-pages doc
This commit is contained in:
parent
c80f23f0db
commit
2d4fc45a0c
@ -1,6 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>hello {{ msg }}</div>
|
<div>
|
||||||
<VuePdfEmbed :source="pdfSource" />
|
<span>
|
||||||
|
<button :disabled="page <= 1" @click="unTurnPage">❮</button>
|
||||||
|
{{ page }} / {{ pageCount }}
|
||||||
|
<button :disabled="page >= pageCount" @click="turnPage">❯</button>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<VuePdfEmbed :source="pdfSource" :page="page"/>
|
||||||
<!-- <canvas id="canvas"></canvas> -->
|
<!-- <canvas id="canvas"></canvas> -->
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -16,23 +22,39 @@ import {
|
|||||||
download_and_decrypt_doc,
|
download_and_decrypt_doc,
|
||||||
} from "../StoredObjectButton/helpers";
|
} from "../StoredObjectButton/helpers";
|
||||||
|
|
||||||
const msg: Ref<string> = ref("world !");
|
const page: Ref<number> = ref(1);
|
||||||
|
const pageCount: Ref<number> = ref(3); //TODO get page count from PDF loaded, can be done with pdfjs (https://stackoverflow.com/questions/10253669/how-to-get-the-number-of-pages-of-a-pdf-uploaded-by-user)
|
||||||
|
let userSignatureZones = {} as SignatureZone;
|
||||||
|
let pdfSource: Ref<string> = ref("");
|
||||||
|
|
||||||
//console.log('signature', window.signature);
|
//console.log('signature', window.signature);
|
||||||
|
|
||||||
const signature = {
|
const signature = {
|
||||||
id: 1,
|
id: 1,
|
||||||
|
// storedObject: {
|
||||||
|
// filename: "gj72nCYsiuysZwZMTMVv5mhqmJdA",
|
||||||
|
// keyInfos: {
|
||||||
|
// alg: "A256CBC",
|
||||||
|
// ext: true,
|
||||||
|
// k: "WwEuXQqv5sJFzAM6P5q7Ecvbl2MiA9mE_MTQ1fAhVsY",
|
||||||
|
// key_ops: ["encrypt", "decrypt"],
|
||||||
|
// kty: "oct",
|
||||||
|
// },
|
||||||
|
// iv: [
|
||||||
|
// 50, 124, 210, 52, 177, 145, 165, 156, 90, 186, 155, 252, 241, 54, 194, 79,
|
||||||
|
// ],
|
||||||
|
// },
|
||||||
storedObject: {
|
storedObject: {
|
||||||
filename: "gj72nCYsiuysZwZMTMVv5mhqmJdA",
|
filename: "U2HmWk5MGkUW1vHRA5sMEMkW9fyf",
|
||||||
keyInfos: {
|
keyInfos: {
|
||||||
alg: "A256CBC",
|
alg: "A256CBC",
|
||||||
ext: true,
|
ext: true,
|
||||||
k: "WwEuXQqv5sJFzAM6P5q7Ecvbl2MiA9mE_MTQ1fAhVsY",
|
k: "3GmJ8UBck3WhpmdoQy7cGQho0J9k9Rxhn23UIhqvpVY",
|
||||||
key_ops: ["encrypt", "decrypt"],
|
key_ops: ["encrypt", "decrypt"],
|
||||||
kty: "oct",
|
kty: "oct",
|
||||||
},
|
},
|
||||||
iv: [
|
iv: [
|
||||||
50, 124, 210, 52, 177, 145, 165, 156, 90, 186, 155, 252, 241, 54, 194, 79,
|
254, 171, 69, 203, 89, 3, 202, 29, 187, 200, 19, 146, 201, 253, 79, 169,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
zones: [
|
zones: [
|
||||||
@ -45,15 +67,20 @@ const signature = {
|
|||||||
width: 80,
|
width: 80,
|
||||||
height: 50,
|
height: 50,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
page: 3,
|
||||||
|
pageWidth: 210,
|
||||||
|
pageHeight: 297,
|
||||||
|
x: 60, //from top-left corner
|
||||||
|
y: 20,
|
||||||
|
width: 80,
|
||||||
|
height: 50,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
let userSignatureZones = {} as SignatureZone;
|
|
||||||
|
|
||||||
const urlInfo = build_download_info_link(signature.storedObject.filename);
|
const urlInfo = build_download_info_link(signature.storedObject.filename);
|
||||||
|
|
||||||
let pdfSource: Ref<string> = ref("");
|
|
||||||
|
|
||||||
async function download_and_open(): Promise<Blob> {
|
async function download_and_open(): Promise<Blob> {
|
||||||
let raw;
|
let raw;
|
||||||
try {
|
try {
|
||||||
@ -63,19 +90,40 @@ async function download_and_open(): Promise<Blob> {
|
|||||||
new Uint8Array(signature.storedObject.iv)
|
new Uint8Array(signature.storedObject.iv)
|
||||||
);
|
);
|
||||||
pdfSource.value = URL.createObjectURL(raw);
|
pdfSource.value = URL.createObjectURL(raw);
|
||||||
setTimeout(() => add_zones(), 2000); //TODO gestion async
|
setTimeout(() => init_pdf(), 2000); //TODO gestion async
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("error while downloading and decrypting document", e);
|
console.error("error while downloading and decrypting document", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
return raw;
|
return raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const init_pdf = () => {
|
||||||
|
const canvas = document.querySelectorAll("canvas")[0];
|
||||||
|
canvas.addEventListener(
|
||||||
|
"pointerup",
|
||||||
|
(e: PointerEvent) => canvas_click(e),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
add_zones();
|
||||||
|
};
|
||||||
|
|
||||||
const canvas_click = (e: PointerEvent) => {
|
const canvas_click = (e: PointerEvent) => {
|
||||||
console.log("click event x and y", e.x, e.y);
|
console.log("click event x and y", e.x, e.y);
|
||||||
//TODO what to do with this: 1) draw the signature if it falls within a zone, 2) output the zone
|
//TODO what to do with this: 1) draw the signature if it falls within a zone, 2) output the zone
|
||||||
userSignatureZones = signature.zones[0]; //TODO for now, need another way to select a zone
|
userSignatureZones = signature.zones[0]; //TODO for now, need another way to select a zone
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const turnPage = () => {
|
||||||
|
page.value = page.value + 1;
|
||||||
|
setTimeout(() => add_zones(), 200);
|
||||||
|
};
|
||||||
|
|
||||||
|
const unTurnPage = () => {
|
||||||
|
page.value = page.value - 1;
|
||||||
|
setTimeout(() => add_zones(), 200);
|
||||||
|
};
|
||||||
|
|
||||||
const draw_zone = (
|
const draw_zone = (
|
||||||
zone: SignatureZone,
|
zone: SignatureZone,
|
||||||
ctx: CanvasRenderingContext2D,
|
ctx: CanvasRenderingContext2D,
|
||||||
@ -93,21 +141,16 @@ const draw_zone = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
const add_zones = () => {
|
const add_zones = () => {
|
||||||
//TODO multipage: draw zones on page change?
|
|
||||||
const canvas = document.querySelectorAll("canvas")[0];
|
const canvas = document.querySelectorAll("canvas")[0];
|
||||||
const ctx = canvas.getContext("2d");
|
const ctx = canvas.getContext("2d");
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
ctx.fillStyle = "green";
|
ctx.fillStyle = "green";
|
||||||
signature.zones.map(
|
signature.zones.map((z) => {
|
||||||
//TODO gestion du numéro de la page
|
if (z.page === page.value) {
|
||||||
(z) => draw_zone(z, ctx, canvas.width, canvas.height)
|
draw_zone(z, ctx, canvas.width, canvas.height);
|
||||||
);
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
canvas.addEventListener(
|
|
||||||
"pointerup",
|
|
||||||
(e: PointerEvent) => canvas_click(e),
|
|
||||||
false
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
download_and_open();
|
download_and_open();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user