Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// import { PDFNet } from "@pdftron/pdfnet-node";
// export const TimestampAndEnableLTV = async (
// docBuffer: ArrayBuffer,
// certPath: string,
// certTSAUrl: string,
// imgBytes: ArrayBuffer,
// coords: any
// ): Promise<ArrayBuffer> => {
// const doc = await PDFNet.PDFDoc.createFromBuffer(docBuffer);
// doc.initSecurityHandler();
// const tst_config = await PDFNet.TimestampingConfiguration.createFromURL(
// certTSAUrl
// );
// const opts = await PDFNet.VerificationOptions.create(
// PDFNet.VerificationOptions.SecurityLevel.e_compatibility_and_archiving
// );
// await opts.addTrustedCertificateUString(certPath);
// const img = await PDFNet.Image.createFromMemory2(doc, imgBytes);
// //make this dynamic with canvas lib
// const imgWidth = 300;
// const imgHeight = 300;
// const pagesForSining = Object.keys(coords).map((k) => {
// return parseInt(k);
// });
// const pages = await doc.getPageCount();
// let result;
// for (let p = 1; p <= pages; p++) {
// if (!pagesForSining.includes(p)) {
// continue;
// }
// const page = await doc.getPage(p);
// const doctimestamp_signature_field =
// await doc.createDigitalSignatureField();
// const widgetAnnot =
// await PDFNet.SignatureWidget.createWithDigitalSignatureField(
// doc,
// new PDFNet.Rect(
// parseFloat(coords[p].x),
// parseFloat(coords[p].x + imgWidth),
// parseFloat(coords[p].y),
// parseFloat(coords[p].y + imgHeight)
// ),
// doctimestamp_signature_field
// );
// await page.annotPushBack(widgetAnnot);
// await widgetAnnot.createSignatureAppearance(img);
// await doctimestamp_signature_field.timestampOnNextSave(tst_config, opts);
// result = await doc.saveMemoryBuffer(
// PDFNet.SDFDoc.SaveOptions.e_incremental
// );
// }
// return result.buffer;
// };