signature: POC of showing a pdf with vue-pdf-embed

This commit is contained in:
nobohan 2024-06-19 11:16:50 +02:00
parent bbfd0caf10
commit 21c1e77d36
2 changed files with 13 additions and 5 deletions

View File

@ -58,6 +58,7 @@
"vue": "^3.2.37",
"vue-i18n": "^9.1.6",
"vue-multiselect": "3.0.0-alpha.2",
"vue-pdf-embed": "^2.0.4",
"vue-toast-notification": "^2.0",
"vuex": "^4.0.0"
},

View File

@ -1,11 +1,13 @@
<template>
<div>hello {{ msg }}</div>
<VuePdfEmbed :source="pdfSource" />
</template>
<script setup lang="ts">
import { ref, Ref } from "vue";
import VuePdfEmbed from "vue-pdf-embed";
import "vue-pdf-embed/dist/style/index.css";
//import { build_download_info_link, download_and_decrypt_doc } from "ChillDocStoreAssets/vuejs/StoredObjectButton/helpers.js";
import {
build_download_info_link,
download_and_decrypt_doc,
@ -18,16 +20,17 @@ const msg: Ref<string> = ref("world !");
const signature = {
id: 1,
storedObject: {
filename: "pKNlhCrQDCRsAuC8vYHDKa",
filename: "V2DZStOWtonw1TiKxzVPDRzlS4YO",
keyInfos: {
alg: "A256CBC",
ext: true,
k: "_VihnD41-VDHlpS-ouwtbMPnu-OXVdtA7ENQWWtAQYM",
k: "x0vaQO0n3QZnipLEmddF3MOF_5_QYnS4g67n0AwZ6YA",
key_ops: ["encrypt", "decrypt"],
kty: "oct",
},
iv: [
86, 231, 83, 148, 117, 107, 149, 173, 130, 19, 105, 194, 224, 145, 8, 48,
150, 175, 71, 136, 62, 123, 230, 141, 72, 204, 116, 110, 139, 22, 246,
114,
],
},
zones: [{ page: 1, origin: [0, 0], x: 10, y: 10 }],
@ -35,6 +38,8 @@ const signature = {
const urlInfo = build_download_info_link(signature.storedObject.filename);
let pdfSource: Ref<string> = ref("");
async function download_and_open(): Promise<Blob> {
let raw;
try {
@ -43,10 +48,12 @@ async function download_and_open(): Promise<Blob> {
signature.storedObject.keyInfos,
new Uint8Array(signature.storedObject.iv)
);
//pdfSource.value = 'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/examples/learning/helloworld.pdf';
pdfSource.value = URL.createObjectURL(raw);
} catch (e) {
console.error("error while downloading and decrypting document", e);
throw e;
};
}
return raw;
}