ebta-workflow-prod 4.0.7 → 4.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@
3
3
  /* eslint-disable @typescript-eslint/no-unsafe-argument */
4
4
  /* eslint-disable prefer-const */
5
5
  import type { IActivityHandler } from "@vertigis/workflow";
6
- import { PDFDocument, degrees, rgb, PDFName, PDFString, TextAlignment, PDFArray, StandardFonts,PDFRef } from 'pdf-lib';
6
+ import { PDFDocument, degrees, rgb, PDFName, PDFString, TextAlignment, PDFArray, StandardFonts, PDFRef } from 'pdf-lib';
7
7
  import axios from 'axios';
8
8
 
9
9
 
@@ -24,13 +24,11 @@ interface PDFMapGeneratorInputs {
24
24
  /**
25
25
  * @displayName Legend img Base64
26
26
  * @description Legend img Base64 created by Legend creator
27
- * @required
28
27
  */
29
28
  LegendImgBase64: string;
30
29
  /**
31
30
  * @displayName Scale Array
32
31
  * @description Array contains the scale numbers catched from each extent
33
- * @required
34
32
  */
35
33
  scaleArray: number[];
36
34
  /**
@@ -90,6 +88,16 @@ interface PDFMapGeneratorInputs {
90
88
  * @description Array of geocoded addresses
91
89
  */
92
90
  addressList: string[];
91
+ /**
92
+ * @displayName specific type name of print template
93
+ * @description specific type name of print template, e.g.'VMP'
94
+ */
95
+ template: string;
96
+ /**
97
+ * @displayName Object to provide extra field detail, by key-value(string)
98
+ * @description Object to provide extra field detail, by key-value(string)
99
+ */
100
+ extraField: object;
93
101
  }
94
102
  /** An interface that defines the outputs of the activity. */
95
103
  interface PDFMapGeneratorOutputs {
@@ -109,7 +117,7 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
109
117
  console.log('EBTA PDFMapGenerator version 1.1')
110
118
  if (typeof fetch !== 'undefined') {
111
119
  const response = await fetch(url, {
112
- mode: 'cors',
120
+ mode: 'cors',
113
121
  credentials: 'omit'
114
122
  });
115
123
  if (!response.ok) {
@@ -129,42 +137,42 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
129
137
  }
130
138
  }
131
139
 
132
- private async reencodeImageToArrayBuffer(arrayBuffer: ArrayBuffer): Promise<ArrayBuffer> {
140
+ private async reencodeImageToArrayBuffer(arrayBuffer: ArrayBuffer): Promise<ArrayBuffer> {
133
141
  const blob = new Blob([arrayBuffer], { type: 'image/jpeg' });
134
142
  const img = new Image();
135
-
143
+
136
144
  // Convert the array buffer to a blob URL
137
145
  img.src = URL.createObjectURL(blob);
138
-
146
+
139
147
  return new Promise<ArrayBuffer>((resolve, reject) => {
140
- img.onload = () => {
141
- const canvas = document.createElement('canvas');
142
- canvas.width = img.width;
143
- canvas.height = img.height;
144
-
145
- const ctx = canvas.getContext('2d');
146
- if (!ctx) return reject(new Error('Canvas context could not be created'));
147
-
148
- ctx.drawImage(img, 0, 0);
149
-
150
- canvas.toBlob((blob) => {
151
- if (!blob) return reject(new Error('Failed to convert canvas to Blob'));
152
-
153
- const reader = new FileReader();
154
- reader.onloadend = () => {
155
- if (reader.result instanceof ArrayBuffer) {
156
- resolve(reader.result);
157
- } else {
158
- reject(new Error('Failed to read Blob as ArrayBuffer'));
159
- }
160
- };
161
- reader.readAsArrayBuffer(blob);
162
- }, 'image/jpeg');
163
- };
164
-
165
- img.onerror = (err) => reject(new Error('Image load error: '));
148
+ img.onload = () => {
149
+ const canvas = document.createElement('canvas');
150
+ canvas.width = img.width;
151
+ canvas.height = img.height;
152
+
153
+ const ctx = canvas.getContext('2d');
154
+ if (!ctx) return reject(new Error('Canvas context could not be created'));
155
+
156
+ ctx.drawImage(img, 0, 0);
157
+
158
+ canvas.toBlob((blob) => {
159
+ if (!blob) return reject(new Error('Failed to convert canvas to Blob'));
160
+
161
+ const reader = new FileReader();
162
+ reader.onloadend = () => {
163
+ if (reader.result instanceof ArrayBuffer) {
164
+ resolve(reader.result);
165
+ } else {
166
+ reject(new Error('Failed to read Blob as ArrayBuffer'));
167
+ }
168
+ };
169
+ reader.readAsArrayBuffer(blob);
170
+ }, 'image/jpeg');
171
+ };
172
+
173
+ img.onerror = (err) => reject(new Error('Image load error: '));
166
174
  });
167
- }
175
+ }
168
176
 
169
177
 
170
178
  private arrayBufferToBase64(buffer: ArrayBuffer): string {
@@ -206,7 +214,7 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
206
214
  return num;
207
215
  }
208
216
 
209
-
217
+
210
218
 
211
219
  /** Perform the execution logic of the activity. */
212
220
  async execute(inputs: PDFMapGeneratorInputs): Promise<PDFMapGeneratorOutputs> {
@@ -234,17 +242,29 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
234
242
  const image3url = 'https://cdn.jsdelivr.net/npm/ebta-resources/resources/prints/dbyd.png'
235
243
  const imageBarurl = 'https://cdn.jsdelivr.net/npm/ebta-resources/resources/prints/Scalebar.png'
236
244
  const imageNorthUrl = 'https://cdn-icons-png.flaticon.com/512/3236/3236586.png'
237
- const image1Buffer = await this.fetchData(image1url);
238
- console.log('Image1 fetched successfully');
239
- const image2Buffer = await this.fetchData(image2url);
240
- console.log('Image2 fetched successfully');
241
- const image3Buffer = await this.fetchData(image3url);
242
- console.log('Image3 fetched successfully');
245
+ let image10Buffer, image1Buffer, image2Buffer, image3Buffer
246
+
247
+ if (inputs.template == 'VMP') {
248
+ const image10kmurl = 'https://ebta.maps.arcgis.com/sharing/rest/content/items/c15211b9826549f69a13c3f3d32a841b/resources/vmp_symbols/speedlimit10.svg'
249
+ image10Buffer = await this.fetchData(image10kmurl);
250
+ console.log('Image10 fetched successfully');
251
+ }
252
+ else {
253
+ image1Buffer = await this.fetchData(image1url);
254
+ console.log('Image1 fetched successfully');
255
+ image2Buffer = await this.fetchData(image2url);
256
+ console.log('Image2 fetched successfully');
257
+ image3Buffer = await this.fetchData(image3url);
258
+ console.log('Image3 fetched successfully');
259
+ }
243
260
  const imageBarBuffer = await this.fetchData(imageBarurl);
244
261
  console.log('Image scale bar fetched successfully');
245
262
  const imageNorthBuffer = await this.fetchData(imageNorthUrl);
246
263
  console.log('Image North Arrow fetched successfully');
247
- const legendBuffer = this.base64ToArrayBuffer(inputs.LegendImgBase64);
264
+ let legendBuffer
265
+ if (inputs.LegendImgBase64) {
266
+ legendBuffer = this.base64ToArrayBuffer(inputs.LegendImgBase64);
267
+ }
248
268
  const filledPDFs: Uint8Array[] = [];
249
269
  for (let i = 0; i < imgBase64Array.length; i++) {
250
270
  let doc = await PDFDocument.load(pdfBuffer);
@@ -259,16 +279,27 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
259
279
  } else if (imgBase64.startsWith('data:image/jpeg;base64,') || imgBase64.startsWith('data:image/jpg;base64,')) {
260
280
  image = await doc.embedJpg(imageBuffer);
261
281
  }
262
- const image1 = await doc.embedPng(image1Buffer);
263
- const image2 = await doc.embedPng(image2Buffer);
264
- const image3 = await doc.embedPng(image3Buffer);
282
+ let image1, image2, image3, image10
283
+ if (inputs.template == 'VMP') {
284
+ image10 = await doc.embedPng(image10Buffer);
285
+ console.log('image10 embed successfully')
286
+ }
287
+ else {
288
+ image1 = await doc.embedPng(image1Buffer);
289
+ image2 = await doc.embedPng(image2Buffer);
290
+ image3 = await doc.embedPng(image3Buffer);
291
+ console.log('image1,2,3 embed successfully')
292
+ }
265
293
  const imageBar = await doc.embedPng(imageBarBuffer);
266
294
  const imageNorth = await doc.embedPng(imageNorthBuffer);
267
295
  let legendImage
268
- if (inputs.LegendImgBase64.startsWith('data:image/png;base64,')) {
269
- legendImage = await doc.embedPng(legendBuffer);
270
- } else if (inputs.LegendImgBase64.startsWith('data:image/jpeg;base64,') || inputs.LegendImgBase64.startsWith('data:image/jpg;base64,')) {
271
- legendImage = await doc.embedJpg(legendBuffer);
296
+ if (inputs.LegendImgBase64) {
297
+ if (inputs.LegendImgBase64.startsWith('data:image/png;base64,')) {
298
+ legendImage = await doc.embedPng(legendBuffer);
299
+ } else if (inputs.LegendImgBase64.startsWith('data:image/jpeg;base64,') || inputs.LegendImgBase64.startsWith('data:image/jpg;base64,')) {
300
+ legendImage = await doc.embedJpg(legendBuffer);
301
+ }
302
+ console.log('legend image embed successfully')
272
303
  }
273
304
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
274
305
  newPage.drawImage(image, {
@@ -277,76 +308,117 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
277
308
  width: width * 0.8113,
278
309
  height: height * 0.8029,
279
310
  });
280
- //Define position & size of legend screeshot, depent on width/height ratio
281
- if (legendImage.width / legendImage.height > 0.259) {
282
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
283
- newPage.drawImage(legendImage, {
284
- x: width * 0.83796,
285
- y: height * (0.94611) - width * 0.14 * (legendImage.height / legendImage.width),
286
- width: width * 0.14,
287
- height: width * 0.14 * (legendImage.height / legendImage.width),
288
- });
289
- }
290
- else {
291
- if (legendImage.width / legendImage.height < 0.259 / 1.6) {
292
- if (legendImage.width / legendImage.height < 0.259 / 3.95) {
293
- if (legendImage.width / legendImage.height < 0.259 / 5.5) {
294
- console.log("split legend into 3 columns");
295
- const fullLegendimg = new Image();
296
- fullLegendimg.src = inputs.LegendImgBase64;
297
- fullLegendimg.onload = async () => {
298
- const neckHeight = Math.floor(legendImage.height * 0.33); // Approximate neck position
299
- const waistHeight = Math.floor(legendImage.height * 0.66); // Approximate waist position
300
- // Neck to Top
301
- const neckUpCanvas = document.createElement('canvas');
302
- neckUpCanvas.width = legendImage.width;
303
- neckUpCanvas.height = neckHeight;
304
- const neckUpCtx = neckUpCanvas.getContext('2d');
305
- neckUpCtx!.drawImage(fullLegendimg, 0, 0, legendImage.width, neckHeight, 0, 0, legendImage.width, neckHeight);
306
- // Waist to Neck
307
- const waistUpCanvas = document.createElement('canvas');
308
- waistUpCanvas.width = legendImage.width;
309
- waistUpCanvas.height = waistHeight - neckHeight;
310
- const waistUpCtx = waistUpCanvas.getContext('2d');
311
- waistUpCtx!.drawImage(fullLegendimg, 0, neckHeight, legendImage.width, waistHeight - neckHeight, 0, 0, legendImage.width, waistHeight - neckHeight);
312
- // Bottom to Waist
313
- const waistDownCanvas = document.createElement('canvas');
314
- waistDownCanvas.width = legendImage.width;
315
- waistDownCanvas.height = legendImage.height - waistHeight;
316
- const waistDownCtx = waistDownCanvas.getContext('2d');
317
- waistDownCtx!.drawImage(fullLegendimg, 0, waistHeight, legendImage.width, legendImage.height - waistHeight, 0, 0, legendImage.width, legendImage.height - waistHeight);
318
- const neckUpBase64 = neckUpCanvas.toDataURL('image/jpeg');
319
- const upBuffer1 = this.base64ToArrayBuffer(neckUpBase64);
320
- const waistUpBase64 = waistUpCanvas.toDataURL('image/jpeg');
321
- const upBuffer2 = this.base64ToArrayBuffer(waistUpBase64);
322
- const waistDownBase64 = waistDownCanvas.toDataURL('image/jpeg');
323
- const downBuffer = this.base64ToArrayBuffer(waistDownBase64);
324
- const LegendNeckUp = await doc.embedJpg(upBuffer1);
325
- const LegendWaistUp = await doc.embedJpg(upBuffer2);
326
- const LegendWaistDown = await doc.embedJpg(downBuffer);
327
- newPage.drawImage(LegendNeckUp, {
328
- x: width * 0.83796,
329
- y: height * 0.94611 - width * 0.14 * 0.33 * (LegendNeckUp.height / LegendNeckUp.width),
330
- width: width * 0.14 * 0.33,
331
- height: width * 0.14 * 0.33 * (LegendNeckUp.height / LegendNeckUp.width),
332
- });
333
- newPage.drawImage(LegendWaistUp, {
334
- x: width * 0.83796 + width * 0.14 * 0.33,
335
- y: height * 0.94611 - width * 0.14 * 0.33 * (LegendWaistUp.height / LegendWaistUp.width),
336
- width: width * 0.14 * 0.33,
337
- height: width * 0.14 * 0.33 * (LegendWaistUp.height / LegendWaistUp.width),
338
- });
339
- newPage.drawImage(LegendWaistDown, {
340
- x: width * 0.83796 + width * 0.14 * .66,
341
- y: height * 0.94611 - width * 0.14 * 0.33 * (LegendWaistDown.height / LegendWaistDown.width),
342
- width: width * 0.14 * 0.33,
343
- height: width * 0.14 * 0.33 * (LegendWaistDown.height / LegendWaistDown.width)
344
- });
311
+ console.log('map image drawn successfully')
312
+ if (inputs.LegendImgBase64) {
313
+ //Define position & size of legend screeshot, depent on width/height ratio
314
+ if (legendImage.width / legendImage.height > 0.259) {
315
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
316
+ newPage.drawImage(legendImage, {
317
+ x: width * 0.83796,
318
+ y: height * (0.94611) - width * 0.14 * (legendImage.height / legendImage.width),
319
+ width: width * 0.14,
320
+ height: width * 0.14 * (legendImage.height / legendImage.width),
321
+ });
322
+ }
323
+ else {
324
+ if (legendImage.width / legendImage.height < 0.259 / 1.6) {
325
+ if (legendImage.width / legendImage.height < 0.259 / 3.95) {
326
+ if (legendImage.width / legendImage.height < 0.259 / 5.5) {
327
+ console.log("split legend into 3 columns");
328
+ const fullLegendimg = new Image();
329
+ fullLegendimg.src = inputs.LegendImgBase64;
330
+ fullLegendimg.onload = async () => {
331
+ const neckHeight = Math.floor(legendImage.height * 0.33); // Approximate neck position
332
+ const waistHeight = Math.floor(legendImage.height * 0.66); // Approximate waist position
333
+ // Neck to Top
334
+ const neckUpCanvas = document.createElement('canvas');
335
+ neckUpCanvas.width = legendImage.width;
336
+ neckUpCanvas.height = neckHeight;
337
+ const neckUpCtx = neckUpCanvas.getContext('2d');
338
+ neckUpCtx!.drawImage(fullLegendimg, 0, 0, legendImage.width, neckHeight, 0, 0, legendImage.width, neckHeight);
339
+ // Waist to Neck
340
+ const waistUpCanvas = document.createElement('canvas');
341
+ waistUpCanvas.width = legendImage.width;
342
+ waistUpCanvas.height = waistHeight - neckHeight;
343
+ const waistUpCtx = waistUpCanvas.getContext('2d');
344
+ waistUpCtx!.drawImage(fullLegendimg, 0, neckHeight, legendImage.width, waistHeight - neckHeight, 0, 0, legendImage.width, waistHeight - neckHeight);
345
+ // Bottom to Waist
346
+ const waistDownCanvas = document.createElement('canvas');
347
+ waistDownCanvas.width = legendImage.width;
348
+ waistDownCanvas.height = legendImage.height - waistHeight;
349
+ const waistDownCtx = waistDownCanvas.getContext('2d');
350
+ waistDownCtx!.drawImage(fullLegendimg, 0, waistHeight, legendImage.width, legendImage.height - waistHeight, 0, 0, legendImage.width, legendImage.height - waistHeight);
351
+ const neckUpBase64 = neckUpCanvas.toDataURL('image/jpeg');
352
+ const upBuffer1 = this.base64ToArrayBuffer(neckUpBase64);
353
+ const waistUpBase64 = waistUpCanvas.toDataURL('image/jpeg');
354
+ const upBuffer2 = this.base64ToArrayBuffer(waistUpBase64);
355
+ const waistDownBase64 = waistDownCanvas.toDataURL('image/jpeg');
356
+ const downBuffer = this.base64ToArrayBuffer(waistDownBase64);
357
+ const LegendNeckUp = await doc.embedJpg(upBuffer1);
358
+ const LegendWaistUp = await doc.embedJpg(upBuffer2);
359
+ const LegendWaistDown = await doc.embedJpg(downBuffer);
360
+ newPage.drawImage(LegendNeckUp, {
361
+ x: width * 0.83796,
362
+ y: height * 0.94611 - width * 0.14 * 0.33 * (LegendNeckUp.height / LegendNeckUp.width),
363
+ width: width * 0.14 * 0.33,
364
+ height: width * 0.14 * 0.33 * (LegendNeckUp.height / LegendNeckUp.width),
365
+ });
366
+ newPage.drawImage(LegendWaistUp, {
367
+ x: width * 0.83796 + width * 0.14 * 0.33,
368
+ y: height * 0.94611 - width * 0.14 * 0.33 * (LegendWaistUp.height / LegendWaistUp.width),
369
+ width: width * 0.14 * 0.33,
370
+ height: width * 0.14 * 0.33 * (LegendWaistUp.height / LegendWaistUp.width),
371
+ });
372
+ newPage.drawImage(LegendWaistDown, {
373
+ x: width * 0.83796 + width * 0.14 * .66,
374
+ y: height * 0.94611 - width * 0.14 * 0.33 * (LegendWaistDown.height / LegendWaistDown.width),
375
+ width: width * 0.14 * 0.33,
376
+ height: width * 0.14 * 0.33 * (LegendWaistDown.height / LegendWaistDown.width)
377
+ });
378
+ }
379
+ }
380
+ else {
381
+ //split into 2 columns & strectch
382
+ console.log("split legend into 2 columns & stretch ")
383
+ const fullLegendimg = new Image();
384
+ fullLegendimg.src = inputs.LegendImgBase64
385
+ fullLegendimg.onload = async () => {
386
+ const halfHeight = Math.floor(legendImage.height / 2)
387
+ const waistUpCanvas = document.createElement('canvas');
388
+ waistUpCanvas.width = legendImage.width;
389
+ waistUpCanvas.height = halfHeight;
390
+ const waistUpCtx = waistUpCanvas.getContext('2d');
391
+ waistUpCtx!.drawImage(fullLegendimg, 0, 0, legendImage.width, halfHeight, 0, 0, legendImage.width, halfHeight);
392
+ const waistDownCanvas = document.createElement('canvas');
393
+ waistDownCanvas.width = legendImage.width;
394
+ waistDownCanvas.height = halfHeight;
395
+ const waistDownCtx = waistDownCanvas.getContext('2d');
396
+ waistDownCtx!.drawImage(fullLegendimg, 0, halfHeight, legendImage.width, halfHeight, 0, 0, legendImage.width, halfHeight);
397
+ const waistUpBase64 = waistUpCanvas.toDataURL('image/jpeg');
398
+ const upBuffer = this.base64ToArrayBuffer(waistUpBase64);
399
+ const waistDownBase64 = waistDownCanvas.toDataURL('image/jpeg');
400
+ const downBuffer = this.base64ToArrayBuffer(waistDownBase64);
401
+ const LegendUp = await doc.embedJpg(upBuffer);
402
+ const LegendDown = await doc.embedJpg(downBuffer);
403
+
404
+ newPage.drawImage(LegendUp, {
405
+ x: width * 0.83796,
406
+ y: height * (0.94611 - 0.77),
407
+ width: height * 0.77 * (LegendUp.width / LegendUp.height),
408
+ height: height * 0.77,
409
+ });
410
+ newPage.drawImage(LegendDown, {
411
+ x: width * 0.83796 + height * 0.77 * (LegendDown.width / LegendDown.height),
412
+ y: height * (0.94611 - 0.77),
413
+ width: height * 0.77 * (LegendDown.width / LegendDown.height),
414
+ height: height * 0.77,
415
+ })
416
+ }
345
417
  }
346
418
  }
347
419
  else {
348
- //split into 2 columns & strectch
349
- console.log("split legend into 2 columns & stretch ")
420
+ //split into 2 columns & no strectch
421
+ console.log("split legend into 2 columns & no strectch")
350
422
  const fullLegendimg = new Image();
351
423
  fullLegendimg.src = inputs.LegendImgBase64
352
424
  fullLegendimg.onload = async () => {
@@ -367,89 +439,64 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
367
439
  const downBuffer = this.base64ToArrayBuffer(waistDownBase64);
368
440
  const LegendUp = await doc.embedJpg(upBuffer);
369
441
  const LegendDown = await doc.embedJpg(downBuffer);
370
-
371
442
  newPage.drawImage(LegendUp, {
372
443
  x: width * 0.83796,
373
- y: height * (0.94611 - 0.77),
374
- width: height * 0.77 * (LegendUp.width / LegendUp.height),
375
- height: height * 0.77,
444
+ y: height * (0.94611) - width * 0.14 * 0.5 * (LegendUp.height / LegendUp.width),
445
+ width: width * 0.14 * 0.5,
446
+ height: width * 0.14 * 0.5 * (LegendUp.height / LegendUp.width),
376
447
  });
377
448
  newPage.drawImage(LegendDown, {
378
- x: width * 0.83796 + height * 0.77 * (LegendDown.width / LegendDown.height),
379
- y: height * (0.94611 - 0.77),
380
- width: height * 0.77 * (LegendDown.width / LegendDown.height),
381
- height: height * 0.77,
449
+ x: width * 0.83796 + width * 0.14 * 0.505,
450
+ y: height * (0.94611) - width * 0.14 * 0.5 * (LegendDown.height / LegendDown.width),
451
+ width: width * 0.14 * 0.5,
452
+ height: width * 0.14 * 0.5 * (LegendDown.height / LegendDown.width)
382
453
  })
383
454
  }
384
455
  }
385
456
  }
386
457
  else {
387
- //split into 2 columns & no strectch
388
- console.log("split legend into 2 columns & no strectch")
389
- const fullLegendimg = new Image();
390
- fullLegendimg.src = inputs.LegendImgBase64
391
- fullLegendimg.onload = async () => {
392
- const halfHeight = Math.floor(legendImage.height / 2)
393
- const waistUpCanvas = document.createElement('canvas');
394
- waistUpCanvas.width = legendImage.width;
395
- waistUpCanvas.height = halfHeight;
396
- const waistUpCtx = waistUpCanvas.getContext('2d');
397
- waistUpCtx!.drawImage(fullLegendimg, 0, 0, legendImage.width, halfHeight, 0, 0, legendImage.width, halfHeight);
398
- const waistDownCanvas = document.createElement('canvas');
399
- waistDownCanvas.width = legendImage.width;
400
- waistDownCanvas.height = halfHeight;
401
- const waistDownCtx = waistDownCanvas.getContext('2d');
402
- waistDownCtx!.drawImage(fullLegendimg, 0, halfHeight, legendImage.width, halfHeight, 0, 0, legendImage.width, halfHeight);
403
- const waistUpBase64 = waistUpCanvas.toDataURL('image/jpeg');
404
- const upBuffer = this.base64ToArrayBuffer(waistUpBase64);
405
- const waistDownBase64 = waistDownCanvas.toDataURL('image/jpeg');
406
- const downBuffer = this.base64ToArrayBuffer(waistDownBase64);
407
- const LegendUp = await doc.embedJpg(upBuffer);
408
- const LegendDown = await doc.embedJpg(downBuffer);
409
- newPage.drawImage(LegendUp, {
410
- x: width * 0.83796,
411
- y: height * (0.94611) - width * 0.14 * 0.5 * (LegendUp.height / LegendUp.width),
412
- width: width * 0.14 * 0.5,
413
- height: width * 0.14 * 0.5 * (LegendUp.height / LegendUp.width),
414
- });
415
- newPage.drawImage(LegendDown, {
416
- x: width * 0.83796 + width * 0.14 * 0.505,
417
- y: height * (0.94611) - width * 0.14 * 0.5 * (LegendDown.height / LegendDown.width),
418
- width: width * 0.14 * 0.5,
419
- height: width * 0.14 * 0.5 * (LegendDown.height / LegendDown.width)
420
- })
421
- }
458
+ // A little bit slim, just stretch
459
+ newPage.drawImage(legendImage, {
460
+ x: width * 0.83796,
461
+ y: height * (0.94611 - 0.77),
462
+ width: height * 0.77 * (legendImage.width / legendImage.height),
463
+ height: height * 0.77,
464
+ });
422
465
  }
423
466
  }
424
- else {
425
- // A little bit slim, just stretch
426
- newPage.drawImage(legendImage, {
427
- x: width * 0.83796,
428
- y: height * (0.94611 - 0.77),
429
- width: height * 0.77 * (legendImage.width / legendImage.height),
430
- height: height * 0.77,
431
- });
432
- }
467
+ console.log('legend image drawn successfully')
433
468
  }
434
469
  const lableSize = 100
435
- newPage.drawImage(image1, {
436
- x: 28,
437
- y: 145,
438
- width: lableSize,
439
- height: lableSize * (image1.height / image1.width),
440
- });
441
- newPage.drawImage(image2, {
442
- x: 28 + lableSize + 6,
443
- y: 145,
444
- width: lableSize,
445
- height: lableSize * (image2.height / image2.width),
446
- });
447
- newPage.drawImage(image3, {
448
- x: 28 + 2 * lableSize + 6 * 2,
449
- y: 145,
450
- width: lableSize * .8,
451
- height: lableSize * .8 * (image3.height / image3.width),
452
- });
470
+ if (inputs.template == 'VMP') {
471
+ newPage.drawImage(image10, {
472
+ x: 28 + 200,
473
+ y: 145,
474
+ width: lableSize,
475
+ height: lableSize * (image10.height / image10.width),
476
+ });
477
+ console.log('image10 drawn successfully')
478
+ }
479
+ else {
480
+ newPage.drawImage(image1, {
481
+ x: 28,
482
+ y: 145,
483
+ width: lableSize,
484
+ height: lableSize * (image1.height / image1.width),
485
+ });
486
+ newPage.drawImage(image2, {
487
+ x: 28 + lableSize + 6,
488
+ y: 145,
489
+ width: lableSize,
490
+ height: lableSize * (image2.height / image2.width),
491
+ });
492
+ newPage.drawImage(image3, {
493
+ x: 28 + 2 * lableSize + 6 * 2,
494
+ y: 145,
495
+ width: lableSize * .8,
496
+ height: lableSize * .8 * (image3.height / image3.width),
497
+ });
498
+ console.log('image1,2,3 drawn successfully')
499
+ }
453
500
  console.log(`success in page. ${i} `)
454
501
  // north arrow
455
502
  const centerX = 40;
@@ -524,6 +571,18 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
524
571
  const revField = form.getTextField('Rev.' + i)
525
572
  revField.setText(inputs.Rev)
526
573
  revField.updateAppearances(font)
574
+ if (inputs.template=='VMP'){
575
+ //supervisor
576
+ const supervisorField = form.getTextField('Supervisor')
577
+ supervisorField.setText(inputs.extraField['supervisor'])
578
+ supervisorField.setAlignment(TextAlignment.Center)
579
+ supervisorField.updateAppearances(font)
580
+ //UHF
581
+ const uhfField = form.getTextField('UHF')
582
+ uhfField.setText(inputs.extraField['UHF'])
583
+ uhfField.setAlignment(TextAlignment.Center)
584
+ uhfField.updateAppearances(font)
585
+ }
527
586
  //date
528
587
  const today = new Date();
529
588
  const formattedDate = today.toLocaleDateString('en-AU');
@@ -553,90 +612,109 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
553
612
  }
554
613
  console.log('Text Fields removal successful')
555
614
  //draw a QR Code image only when Qr URL is given && QR image not given
615
+ const boldFont = await doc.embedFont(StandardFonts.HelveticaBold);
556
616
 
557
- if (inputs.buttonLink && inputs.buttonLink.length>0) {
558
- const buttonX=width * 0.74
559
- const buttonY=130
560
- const buttonW=90
561
- const buttonH=50
562
- const buttonBackgroundUrl = 'https://cdn.jsdelivr.net/npm/ebta-resources/resources/prints/gis-button.png'
563
- const buttonBackgroundBuffer = await this.fetchData(buttonBackgroundUrl);
564
- const buttonEmbed = await doc.embedPng(buttonBackgroundBuffer);
565
- newPage.drawImage(buttonEmbed, {
566
- x: buttonX,
567
- y: buttonY,
568
- width: buttonW,
569
- height: buttonH,
570
- });
571
- const boldFont = await doc.embedFont(StandardFonts.HelveticaBold);
572
- newPage.drawText('Go to EBTA GIS', {
573
- x: buttonX+5,
574
- y: buttonY+22,
575
- size: 10,
576
- color: rgb(1, 1, 1), // White color
577
- font: boldFont,
578
- });
617
+ if (inputs.template == 'VMP') {
618
+ newPage.drawText('Maximum Speed 10KM/h within Work Area', {
619
+ x: 28,
620
+ y: 145,
621
+ size: 10.5,
622
+ color: rgb(255, 255, 255), // White color
623
+ font: boldFont,
624
+ });
625
+ newPage.drawText('Maximum Speed 10KM/h within Work Area', {
626
+ x: 28,
627
+ y: 145,
628
+ size: 10,
629
+ color: rgb(255, 0, 0), // red color
630
+ font: boldFont,
631
+ });
632
+ }
579
633
 
580
- const existingAnnots = newPage.node.lookup(PDFName.of('Annots'));
581
- let annotationsArray = existingAnnots instanceof PDFArray ? existingAnnots : doc.context.obj([]);
582
-
583
-
584
- const linkAnnotation = doc.context.register(
585
- doc.context.obj({
586
- Type: 'Annot',
587
- Subtype: 'Link',
588
- Rect: [buttonX, buttonY, buttonX+buttonW,buttonY+buttonH],
589
- Border: [0, 0, 0],
590
- A: {
591
- Type: 'Action',
592
- S: 'URI',
593
- URI: PDFString.of((i <= (inputs.buttonLink.length - 1)) ? inputs.buttonLink[i] : inputs.buttonLink[inputs.buttonLink.length - 1]),
594
- },
595
- })
596
- );
597
- // Append the new annotation to the existing ones
598
- annotationsArray.push(linkAnnotation);
599
- // Set the updated annotations array back to the page
600
- newPage.node.set(PDFName.of('Annots'), annotationsArray);
601
- }
634
+ if (inputs.buttonLink && inputs.buttonLink.length > 0) {
635
+ const buttonX = width * 0.74
636
+ const buttonY = 130
637
+ const buttonW = 90
638
+ const buttonH = 50
639
+ const buttonBackgroundUrl = 'https://cdn.jsdelivr.net/npm/ebta-resources/resources/prints/gis-button.png'
640
+ const buttonBackgroundBuffer = await this.fetchData(buttonBackgroundUrl);
641
+ const buttonEmbed = await doc.embedPng(buttonBackgroundBuffer);
642
+ newPage.drawImage(buttonEmbed, {
643
+ x: buttonX,
644
+ y: buttonY,
645
+ width: buttonW,
646
+ height: buttonH,
647
+ });
602
648
 
603
- if (inputs.QrUrl && inputs.QrUrl.length > 0 && (inputs.QrCodeImage == undefined)) {
604
- //QR Code
605
- // eslint-disable-next-line @typescript-eslint/no-var-requires
606
- const QRCode = require('qrcode');
607
- const qrDataUrl = (i <= (inputs.QrUrl.length - 1)) ? await QRCode.toDataURL(inputs.QrUrl[i]) : await QRCode.toDataURL(inputs.QrUrl[inputs.QrUrl.length - 1]);
608
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
609
- const qrImageBytes = await fetch(qrDataUrl).then(res => res.arrayBuffer());
610
- const qrImage = await doc.embedPng(qrImageBytes);
611
- newPage.drawImage(qrImage, {
612
- x: 210,
613
- y: 93,
614
- width: 40,
615
- height: 40,
616
- });
649
+ newPage.drawText('Go to EBTA GIS', {
650
+ x: buttonX + 5,
651
+ y: buttonY + 22,
652
+ size: 10,
653
+ color: rgb(1, 1, 1), // White color
654
+ font: boldFont,
655
+ });
656
+
657
+
658
+ const existingAnnots = newPage.node.lookup(PDFName.of('Annots'));
659
+ let annotationsArray = existingAnnots instanceof PDFArray ? existingAnnots : doc.context.obj([]);
660
+
661
+
662
+ const linkAnnotation = doc.context.register(
663
+ doc.context.obj({
664
+ Type: 'Annot',
665
+ Subtype: 'Link',
666
+ Rect: [buttonX, buttonY, buttonX + buttonW, buttonY + buttonH],
667
+ Border: [0, 0, 0],
668
+ A: {
669
+ Type: 'Action',
670
+ S: 'URI',
671
+ URI: PDFString.of((i <= (inputs.buttonLink.length - 1)) ? inputs.buttonLink[i] : inputs.buttonLink[inputs.buttonLink.length - 1]),
672
+ },
673
+ })
674
+ );
675
+ // Append the new annotation to the existing ones
676
+ annotationsArray.push(linkAnnotation);
677
+ // Set the updated annotations array back to the page
678
+ newPage.node.set(PDFName.of('Annots'), annotationsArray);
679
+ }
680
+
681
+ if (inputs.QrUrl && inputs.QrUrl.length > 0 && (inputs.QrCodeImage == undefined)) {
682
+ //QR Code
683
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
684
+ const QRCode = require('qrcode');
685
+ const qrDataUrl = (i <= (inputs.QrUrl.length - 1)) ? await QRCode.toDataURL(inputs.QrUrl[i]) : await QRCode.toDataURL(inputs.QrUrl[inputs.QrUrl.length - 1]);
686
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
687
+ const qrImageBytes = await fetch(qrDataUrl).then(res => res.arrayBuffer());
688
+ const qrImage = await doc.embedPng(qrImageBytes);
689
+ newPage.drawImage(qrImage, {
690
+ x: 210,
691
+ y: 93,
692
+ width: 40,
693
+ height: 40,
694
+ });
695
+
696
+ const existingAnnots = newPage.node.lookup(PDFName.of('Annots'));
697
+ let annotationsArray = existingAnnots instanceof PDFArray ? existingAnnots : doc.context.obj([]);
698
+ const linkAnnotation = doc.context.register(
699
+ doc.context.obj({
700
+ Type: 'Annot',
701
+ Subtype: 'Link',
702
+ Rect: [210, 93, 250, 93 + 40],
703
+ Border: [0, 0, 0],
704
+ A: {
705
+ Type: 'Action',
706
+ S: 'URI',
707
+ URI: PDFString.of((i <= (inputs.QrUrl.length - 1)) ? inputs.QrUrl[i] : inputs.QrUrl[inputs.QrUrl.length - 1]),
708
+ },
709
+ })
710
+ );
711
+ // Append the new annotation to the existing ones
712
+ annotationsArray.push(linkAnnotation);
713
+ // Set the updated annotations array back to the page
714
+ newPage.node.set(PDFName.of('Annots'), annotationsArray);
715
+ }
617
716
 
618
- const existingAnnots = newPage.node.lookup(PDFName.of('Annots'));
619
- let annotationsArray = existingAnnots instanceof PDFArray ? existingAnnots : doc.context.obj([]);
620
- const linkAnnotation = doc.context.register(
621
- doc.context.obj({
622
- Type: 'Annot',
623
- Subtype: 'Link',
624
- Rect: [210, 93, 250, 93+40],
625
- Border: [0, 0, 0],
626
- A: {
627
- Type: 'Action',
628
- S: 'URI',
629
- URI: PDFString.of((i <= (inputs.QrUrl.length - 1)) ? inputs.QrUrl[i] : inputs.QrUrl[inputs.QrUrl.length - 1]),
630
- },
631
- })
632
- );
633
- // Append the new annotation to the existing ones
634
- annotationsArray.push(linkAnnotation);
635
- // Set the updated annotations array back to the page
636
- newPage.node.set(PDFName.of('Annots'), annotationsArray);
637
- }
638
717
 
639
-
640
718
  if (inputs.QrCodeImage && inputs.QrCodeImage.length > 0) {
641
719
  const inputQrImageUrl = (i <= (inputs.QrCodeImage.length - 1)) ? inputs.QrCodeImage[i] : inputs.QrCodeImage[inputs.QrCodeImage.length - 1]
642
720
  const inputQrBuffer = await this.fetchData(inputQrImageUrl);
@@ -644,13 +722,13 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
644
722
  let inputQRembed
645
723
  console.log(inputQrImageUrl);
646
724
  console.log(inputQrImageUrl.toLowerCase().includes(".png"));
647
- console.log(inputQrImageUrl.toLowerCase().includes(".jpg")||inputQrImageUrl.toLowerCase().includes(".jpeg"));
648
- if (inputQrImageUrl.toLowerCase().includes(".png")){
649
- inputQRembed = await doc.embedPng(inputQrBuffer);
650
- console.log('embed QR Code image as png');
725
+ console.log(inputQrImageUrl.toLowerCase().includes(".jpg") || inputQrImageUrl.toLowerCase().includes(".jpeg"));
726
+ if (inputQrImageUrl.toLowerCase().includes(".png")) {
727
+ inputQRembed = await doc.embedPng(inputQrBuffer);
728
+ console.log('embed QR Code image as png');
651
729
  }
652
-
653
- else if (inputQrImageUrl.toLowerCase().includes(".jpg")||inputQrImageUrl.toLowerCase().includes(".jpeg")){
730
+
731
+ else if (inputQrImageUrl.toLowerCase().includes(".jpg") || inputQrImageUrl.toLowerCase().includes(".jpeg")) {
654
732
  console.log(inputQrBuffer)
655
733
  const dataView = new DataView(inputQrBuffer);
656
734
  console.log(dataView)
@@ -665,11 +743,11 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
665
743
  console.log('SOI marker not found but forcing to be correct.');
666
744
  let fixedArrayBuffer = await this.reencodeImageToArrayBuffer(inputQrBuffer)
667
745
  inputQRembed = await doc.embedJpg(fixedArrayBuffer);
668
- }
746
+ }
669
747
  console.log('embed QR Code image as jpg successful');
670
748
  }
671
749
 
672
-
750
+
673
751
  newPage.drawImage(inputQRembed, {
674
752
  x: 210,
675
753
  y: 93,
@@ -699,7 +777,7 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
699
777
  filledPDFs.push(await doc.save());
700
778
 
701
779
  }
702
-
780
+
703
781
  const finalPDF = await PDFDocument.create();
704
782
 
705
783
  // Copy pages from all filled PDFs into the final document
@@ -711,6 +789,7 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
711
789
 
712
790
  const pdfBytes = await finalPDF.save();
713
791
  const base64String = this.arrayBufferToBase64(pdfBytes);
792
+ //was and still working fine, ignore the bug report
714
793
  const downloadUrl = this.createDownloadUrl(base64String);
715
794
  console.log('pdf file created and ready to download');
716
795
  return {