ebta-workflow-prod 4.0.7 → 4.0.8
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.
- package/build/activitypack.json +1 -1
- package/build/main.js +2 -2
- package/package.json +1 -1
- package/src/activities/PDFMapGenerator.ts +318 -274
- package/src/elements/Viewer360.tsx +0 -6
- package/src/index.ts +0 -3
- package/src/elements/Viewer360V2.tsx +0 -116
|
@@ -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,11 @@ 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;
|
|
93
96
|
}
|
|
94
97
|
/** An interface that defines the outputs of the activity. */
|
|
95
98
|
interface PDFMapGeneratorOutputs {
|
|
@@ -109,7 +112,7 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
109
112
|
console.log('EBTA PDFMapGenerator version 1.1')
|
|
110
113
|
if (typeof fetch !== 'undefined') {
|
|
111
114
|
const response = await fetch(url, {
|
|
112
|
-
mode:
|
|
115
|
+
mode: 'cors',
|
|
113
116
|
credentials: 'omit'
|
|
114
117
|
});
|
|
115
118
|
if (!response.ok) {
|
|
@@ -129,42 +132,42 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
134
|
|
|
132
|
-
|
|
135
|
+
private async reencodeImageToArrayBuffer(arrayBuffer: ArrayBuffer): Promise<ArrayBuffer> {
|
|
133
136
|
const blob = new Blob([arrayBuffer], { type: 'image/jpeg' });
|
|
134
137
|
const img = new Image();
|
|
135
|
-
|
|
138
|
+
|
|
136
139
|
// Convert the array buffer to a blob URL
|
|
137
140
|
img.src = URL.createObjectURL(blob);
|
|
138
|
-
|
|
141
|
+
|
|
139
142
|
return new Promise<ArrayBuffer>((resolve, reject) => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
143
|
+
img.onload = () => {
|
|
144
|
+
const canvas = document.createElement('canvas');
|
|
145
|
+
canvas.width = img.width;
|
|
146
|
+
canvas.height = img.height;
|
|
147
|
+
|
|
148
|
+
const ctx = canvas.getContext('2d');
|
|
149
|
+
if (!ctx) return reject(new Error('Canvas context could not be created'));
|
|
150
|
+
|
|
151
|
+
ctx.drawImage(img, 0, 0);
|
|
152
|
+
|
|
153
|
+
canvas.toBlob((blob) => {
|
|
154
|
+
if (!blob) return reject(new Error('Failed to convert canvas to Blob'));
|
|
155
|
+
|
|
156
|
+
const reader = new FileReader();
|
|
157
|
+
reader.onloadend = () => {
|
|
158
|
+
if (reader.result instanceof ArrayBuffer) {
|
|
159
|
+
resolve(reader.result);
|
|
160
|
+
} else {
|
|
161
|
+
reject(new Error('Failed to read Blob as ArrayBuffer'));
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
reader.readAsArrayBuffer(blob);
|
|
165
|
+
}, 'image/jpeg');
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
img.onerror = (err) => reject(new Error('Image load error: '));
|
|
166
169
|
});
|
|
167
|
-
|
|
170
|
+
}
|
|
168
171
|
|
|
169
172
|
|
|
170
173
|
private arrayBufferToBase64(buffer: ArrayBuffer): string {
|
|
@@ -206,7 +209,7 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
206
209
|
return num;
|
|
207
210
|
}
|
|
208
211
|
|
|
209
|
-
|
|
212
|
+
|
|
210
213
|
|
|
211
214
|
/** Perform the execution logic of the activity. */
|
|
212
215
|
async execute(inputs: PDFMapGeneratorInputs): Promise<PDFMapGeneratorOutputs> {
|
|
@@ -234,17 +237,29 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
234
237
|
const image3url = 'https://cdn.jsdelivr.net/npm/ebta-resources/resources/prints/dbyd.png'
|
|
235
238
|
const imageBarurl = 'https://cdn.jsdelivr.net/npm/ebta-resources/resources/prints/Scalebar.png'
|
|
236
239
|
const imageNorthUrl = 'https://cdn-icons-png.flaticon.com/512/3236/3236586.png'
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
let image10Buffer, image1Buffer, image2Buffer, image3Buffer
|
|
241
|
+
|
|
242
|
+
if (inputs.template == 'VMP') {
|
|
243
|
+
const image10kmurl = 'https://ebta.maps.arcgis.com/sharing/rest/content/items/c15211b9826549f69a13c3f3d32a841b/resources/vmp_symbols/speedlimit10.svg'
|
|
244
|
+
image10Buffer = await this.fetchData(image10kmurl);
|
|
245
|
+
console.log('Image10 fetched successfully');
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
image1Buffer = await this.fetchData(image1url);
|
|
249
|
+
console.log('Image1 fetched successfully');
|
|
250
|
+
image2Buffer = await this.fetchData(image2url);
|
|
251
|
+
console.log('Image2 fetched successfully');
|
|
252
|
+
image3Buffer = await this.fetchData(image3url);
|
|
253
|
+
console.log('Image3 fetched successfully');
|
|
254
|
+
}
|
|
243
255
|
const imageBarBuffer = await this.fetchData(imageBarurl);
|
|
244
256
|
console.log('Image scale bar fetched successfully');
|
|
245
257
|
const imageNorthBuffer = await this.fetchData(imageNorthUrl);
|
|
246
258
|
console.log('Image North Arrow fetched successfully');
|
|
247
|
-
|
|
259
|
+
let legendBuffer
|
|
260
|
+
if (inputs.LegendImgBase64) {
|
|
261
|
+
legendBuffer = this.base64ToArrayBuffer(inputs.LegendImgBase64);
|
|
262
|
+
}
|
|
248
263
|
const filledPDFs: Uint8Array[] = [];
|
|
249
264
|
for (let i = 0; i < imgBase64Array.length; i++) {
|
|
250
265
|
let doc = await PDFDocument.load(pdfBuffer);
|
|
@@ -259,16 +274,24 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
259
274
|
} else if (imgBase64.startsWith('data:image/jpeg;base64,') || imgBase64.startsWith('data:image/jpg;base64,')) {
|
|
260
275
|
image = await doc.embedJpg(imageBuffer);
|
|
261
276
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
277
|
+
let image1, image2, image3, image10
|
|
278
|
+
if (inputs.template == 'VMP') {
|
|
279
|
+
image10 = await doc.embedPng(image10Buffer);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
image1 = await doc.embedPng(image1Buffer);
|
|
283
|
+
image2 = await doc.embedPng(image2Buffer);
|
|
284
|
+
image3 = await doc.embedPng(image3Buffer);
|
|
285
|
+
}
|
|
265
286
|
const imageBar = await doc.embedPng(imageBarBuffer);
|
|
266
287
|
const imageNorth = await doc.embedPng(imageNorthBuffer);
|
|
267
288
|
let legendImage
|
|
268
|
-
if (inputs.LegendImgBase64
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
289
|
+
if (inputs.LegendImgBase64) {
|
|
290
|
+
if (inputs.LegendImgBase64.startsWith('data:image/png;base64,')) {
|
|
291
|
+
legendImage = await doc.embedPng(legendBuffer);
|
|
292
|
+
} else if (inputs.LegendImgBase64.startsWith('data:image/jpeg;base64,') || inputs.LegendImgBase64.startsWith('data:image/jpg;base64,')) {
|
|
293
|
+
legendImage = await doc.embedJpg(legendBuffer);
|
|
294
|
+
}
|
|
272
295
|
}
|
|
273
296
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
274
297
|
newPage.drawImage(image, {
|
|
@@ -277,76 +300,116 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
277
300
|
width: width * 0.8113,
|
|
278
301
|
height: height * 0.8029,
|
|
279
302
|
});
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
if (legendImage.width / legendImage.height < 0.259 /
|
|
293
|
-
if (legendImage.width / legendImage.height < 0.259 /
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
303
|
+
if (inputs.LegendImgBase64) {
|
|
304
|
+
//Define position & size of legend screeshot, depent on width/height ratio
|
|
305
|
+
if (legendImage.width / legendImage.height > 0.259) {
|
|
306
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
307
|
+
newPage.drawImage(legendImage, {
|
|
308
|
+
x: width * 0.83796,
|
|
309
|
+
y: height * (0.94611) - width * 0.14 * (legendImage.height / legendImage.width),
|
|
310
|
+
width: width * 0.14,
|
|
311
|
+
height: width * 0.14 * (legendImage.height / legendImage.width),
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
if (legendImage.width / legendImage.height < 0.259 / 1.6) {
|
|
316
|
+
if (legendImage.width / legendImage.height < 0.259 / 3.95) {
|
|
317
|
+
if (legendImage.width / legendImage.height < 0.259 / 5.5) {
|
|
318
|
+
console.log("split legend into 3 columns");
|
|
319
|
+
const fullLegendimg = new Image();
|
|
320
|
+
fullLegendimg.src = inputs.LegendImgBase64;
|
|
321
|
+
fullLegendimg.onload = async () => {
|
|
322
|
+
const neckHeight = Math.floor(legendImage.height * 0.33); // Approximate neck position
|
|
323
|
+
const waistHeight = Math.floor(legendImage.height * 0.66); // Approximate waist position
|
|
324
|
+
// Neck to Top
|
|
325
|
+
const neckUpCanvas = document.createElement('canvas');
|
|
326
|
+
neckUpCanvas.width = legendImage.width;
|
|
327
|
+
neckUpCanvas.height = neckHeight;
|
|
328
|
+
const neckUpCtx = neckUpCanvas.getContext('2d');
|
|
329
|
+
neckUpCtx!.drawImage(fullLegendimg, 0, 0, legendImage.width, neckHeight, 0, 0, legendImage.width, neckHeight);
|
|
330
|
+
// Waist to Neck
|
|
331
|
+
const waistUpCanvas = document.createElement('canvas');
|
|
332
|
+
waistUpCanvas.width = legendImage.width;
|
|
333
|
+
waistUpCanvas.height = waistHeight - neckHeight;
|
|
334
|
+
const waistUpCtx = waistUpCanvas.getContext('2d');
|
|
335
|
+
waistUpCtx!.drawImage(fullLegendimg, 0, neckHeight, legendImage.width, waistHeight - neckHeight, 0, 0, legendImage.width, waistHeight - neckHeight);
|
|
336
|
+
// Bottom to Waist
|
|
337
|
+
const waistDownCanvas = document.createElement('canvas');
|
|
338
|
+
waistDownCanvas.width = legendImage.width;
|
|
339
|
+
waistDownCanvas.height = legendImage.height - waistHeight;
|
|
340
|
+
const waistDownCtx = waistDownCanvas.getContext('2d');
|
|
341
|
+
waistDownCtx!.drawImage(fullLegendimg, 0, waistHeight, legendImage.width, legendImage.height - waistHeight, 0, 0, legendImage.width, legendImage.height - waistHeight);
|
|
342
|
+
const neckUpBase64 = neckUpCanvas.toDataURL('image/jpeg');
|
|
343
|
+
const upBuffer1 = this.base64ToArrayBuffer(neckUpBase64);
|
|
344
|
+
const waistUpBase64 = waistUpCanvas.toDataURL('image/jpeg');
|
|
345
|
+
const upBuffer2 = this.base64ToArrayBuffer(waistUpBase64);
|
|
346
|
+
const waistDownBase64 = waistDownCanvas.toDataURL('image/jpeg');
|
|
347
|
+
const downBuffer = this.base64ToArrayBuffer(waistDownBase64);
|
|
348
|
+
const LegendNeckUp = await doc.embedJpg(upBuffer1);
|
|
349
|
+
const LegendWaistUp = await doc.embedJpg(upBuffer2);
|
|
350
|
+
const LegendWaistDown = await doc.embedJpg(downBuffer);
|
|
351
|
+
newPage.drawImage(LegendNeckUp, {
|
|
352
|
+
x: width * 0.83796,
|
|
353
|
+
y: height * 0.94611 - width * 0.14 * 0.33 * (LegendNeckUp.height / LegendNeckUp.width),
|
|
354
|
+
width: width * 0.14 * 0.33,
|
|
355
|
+
height: width * 0.14 * 0.33 * (LegendNeckUp.height / LegendNeckUp.width),
|
|
356
|
+
});
|
|
357
|
+
newPage.drawImage(LegendWaistUp, {
|
|
358
|
+
x: width * 0.83796 + width * 0.14 * 0.33,
|
|
359
|
+
y: height * 0.94611 - width * 0.14 * 0.33 * (LegendWaistUp.height / LegendWaistUp.width),
|
|
360
|
+
width: width * 0.14 * 0.33,
|
|
361
|
+
height: width * 0.14 * 0.33 * (LegendWaistUp.height / LegendWaistUp.width),
|
|
362
|
+
});
|
|
363
|
+
newPage.drawImage(LegendWaistDown, {
|
|
364
|
+
x: width * 0.83796 + width * 0.14 * .66,
|
|
365
|
+
y: height * 0.94611 - width * 0.14 * 0.33 * (LegendWaistDown.height / LegendWaistDown.width),
|
|
366
|
+
width: width * 0.14 * 0.33,
|
|
367
|
+
height: width * 0.14 * 0.33 * (LegendWaistDown.height / LegendWaistDown.width)
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
//split into 2 columns & strectch
|
|
373
|
+
console.log("split legend into 2 columns & stretch ")
|
|
374
|
+
const fullLegendimg = new Image();
|
|
375
|
+
fullLegendimg.src = inputs.LegendImgBase64
|
|
376
|
+
fullLegendimg.onload = async () => {
|
|
377
|
+
const halfHeight = Math.floor(legendImage.height / 2)
|
|
378
|
+
const waistUpCanvas = document.createElement('canvas');
|
|
379
|
+
waistUpCanvas.width = legendImage.width;
|
|
380
|
+
waistUpCanvas.height = halfHeight;
|
|
381
|
+
const waistUpCtx = waistUpCanvas.getContext('2d');
|
|
382
|
+
waistUpCtx!.drawImage(fullLegendimg, 0, 0, legendImage.width, halfHeight, 0, 0, legendImage.width, halfHeight);
|
|
383
|
+
const waistDownCanvas = document.createElement('canvas');
|
|
384
|
+
waistDownCanvas.width = legendImage.width;
|
|
385
|
+
waistDownCanvas.height = halfHeight;
|
|
386
|
+
const waistDownCtx = waistDownCanvas.getContext('2d');
|
|
387
|
+
waistDownCtx!.drawImage(fullLegendimg, 0, halfHeight, legendImage.width, halfHeight, 0, 0, legendImage.width, halfHeight);
|
|
388
|
+
const waistUpBase64 = waistUpCanvas.toDataURL('image/jpeg');
|
|
389
|
+
const upBuffer = this.base64ToArrayBuffer(waistUpBase64);
|
|
390
|
+
const waistDownBase64 = waistDownCanvas.toDataURL('image/jpeg');
|
|
391
|
+
const downBuffer = this.base64ToArrayBuffer(waistDownBase64);
|
|
392
|
+
const LegendUp = await doc.embedJpg(upBuffer);
|
|
393
|
+
const LegendDown = await doc.embedJpg(downBuffer);
|
|
394
|
+
|
|
395
|
+
newPage.drawImage(LegendUp, {
|
|
396
|
+
x: width * 0.83796,
|
|
397
|
+
y: height * (0.94611 - 0.77),
|
|
398
|
+
width: height * 0.77 * (LegendUp.width / LegendUp.height),
|
|
399
|
+
height: height * 0.77,
|
|
400
|
+
});
|
|
401
|
+
newPage.drawImage(LegendDown, {
|
|
402
|
+
x: width * 0.83796 + height * 0.77 * (LegendDown.width / LegendDown.height),
|
|
403
|
+
y: height * (0.94611 - 0.77),
|
|
404
|
+
width: height * 0.77 * (LegendDown.width / LegendDown.height),
|
|
405
|
+
height: height * 0.77,
|
|
406
|
+
})
|
|
407
|
+
}
|
|
345
408
|
}
|
|
346
409
|
}
|
|
347
410
|
else {
|
|
348
|
-
//split into 2 columns & strectch
|
|
349
|
-
console.log("split legend into 2 columns
|
|
411
|
+
//split into 2 columns & no strectch
|
|
412
|
+
console.log("split legend into 2 columns & no strectch")
|
|
350
413
|
const fullLegendimg = new Image();
|
|
351
414
|
fullLegendimg.src = inputs.LegendImgBase64
|
|
352
415
|
fullLegendimg.onload = async () => {
|
|
@@ -367,89 +430,61 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
367
430
|
const downBuffer = this.base64ToArrayBuffer(waistDownBase64);
|
|
368
431
|
const LegendUp = await doc.embedJpg(upBuffer);
|
|
369
432
|
const LegendDown = await doc.embedJpg(downBuffer);
|
|
370
|
-
|
|
371
433
|
newPage.drawImage(LegendUp, {
|
|
372
434
|
x: width * 0.83796,
|
|
373
|
-
y: height * (0.94611 - 0.
|
|
374
|
-
width:
|
|
375
|
-
height:
|
|
435
|
+
y: height * (0.94611) - width * 0.14 * 0.5 * (LegendUp.height / LegendUp.width),
|
|
436
|
+
width: width * 0.14 * 0.5,
|
|
437
|
+
height: width * 0.14 * 0.5 * (LegendUp.height / LegendUp.width),
|
|
376
438
|
});
|
|
377
439
|
newPage.drawImage(LegendDown, {
|
|
378
|
-
x: width * 0.83796 +
|
|
379
|
-
y: height * (0.94611 - 0.
|
|
380
|
-
width:
|
|
381
|
-
height:
|
|
440
|
+
x: width * 0.83796 + width * 0.14 * 0.505,
|
|
441
|
+
y: height * (0.94611) - width * 0.14 * 0.5 * (LegendDown.height / LegendDown.width),
|
|
442
|
+
width: width * 0.14 * 0.5,
|
|
443
|
+
height: width * 0.14 * 0.5 * (LegendDown.height / LegendDown.width)
|
|
382
444
|
})
|
|
383
445
|
}
|
|
384
446
|
}
|
|
385
447
|
}
|
|
386
448
|
else {
|
|
387
|
-
//
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
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
|
-
}
|
|
449
|
+
// A little bit slim, just stretch
|
|
450
|
+
newPage.drawImage(legendImage, {
|
|
451
|
+
x: width * 0.83796,
|
|
452
|
+
y: height * (0.94611 - 0.77),
|
|
453
|
+
width: height * 0.77 * (legendImage.width / legendImage.height),
|
|
454
|
+
height: height * 0.77,
|
|
455
|
+
});
|
|
422
456
|
}
|
|
423
457
|
}
|
|
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
|
-
}
|
|
433
458
|
}
|
|
434
459
|
const lableSize = 100
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
460
|
+
if (inputs.template == 'VMP') {
|
|
461
|
+
newPage.drawImage(image10, {
|
|
462
|
+
x: 28+200,
|
|
463
|
+
y: 145,
|
|
464
|
+
width: lableSize,
|
|
465
|
+
height: lableSize * (image10.height / image10.width),
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
newPage.drawImage(image1, {
|
|
470
|
+
x: 28,
|
|
471
|
+
y: 145,
|
|
472
|
+
width: lableSize,
|
|
473
|
+
height: lableSize * (image1.height / image1.width),
|
|
474
|
+
});
|
|
475
|
+
newPage.drawImage(image2, {
|
|
476
|
+
x: 28 + lableSize + 6,
|
|
477
|
+
y: 145,
|
|
478
|
+
width: lableSize,
|
|
479
|
+
height: lableSize * (image2.height / image2.width),
|
|
480
|
+
});
|
|
481
|
+
newPage.drawImage(image3, {
|
|
482
|
+
x: 28 + 2 * lableSize + 6 * 2,
|
|
483
|
+
y: 145,
|
|
484
|
+
width: lableSize * .8,
|
|
485
|
+
height: lableSize * .8 * (image3.height / image3.width),
|
|
486
|
+
});
|
|
487
|
+
}
|
|
453
488
|
console.log(`success in page. ${i} `)
|
|
454
489
|
// north arrow
|
|
455
490
|
const centerX = 40;
|
|
@@ -554,89 +589,98 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
554
589
|
console.log('Text Fields removal successful')
|
|
555
590
|
//draw a QR Code image only when Qr URL is given && QR image not given
|
|
556
591
|
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
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);
|
|
592
|
+
if (inputs.buttonLink && inputs.buttonLink.length > 0) {
|
|
593
|
+
const buttonX = width * 0.74
|
|
594
|
+
const buttonY = 130
|
|
595
|
+
const buttonW = 90
|
|
596
|
+
const buttonH = 50
|
|
597
|
+
const buttonBackgroundUrl = 'https://cdn.jsdelivr.net/npm/ebta-resources/resources/prints/gis-button.png'
|
|
598
|
+
const buttonBackgroundBuffer = await this.fetchData(buttonBackgroundUrl);
|
|
599
|
+
const buttonEmbed = await doc.embedPng(buttonBackgroundBuffer);
|
|
600
|
+
newPage.drawImage(buttonEmbed, {
|
|
601
|
+
x: buttonX,
|
|
602
|
+
y: buttonY,
|
|
603
|
+
width: buttonW,
|
|
604
|
+
height: buttonH,
|
|
605
|
+
});
|
|
606
|
+
const boldFont = await doc.embedFont(StandardFonts.HelveticaBold);
|
|
607
|
+
newPage.drawText('Go to EBTA GIS', {
|
|
608
|
+
x: buttonX + 5,
|
|
609
|
+
y: buttonY + 22,
|
|
610
|
+
size: 10,
|
|
611
|
+
color: rgb(1, 1, 1), // White color
|
|
612
|
+
font: boldFont,
|
|
613
|
+
});
|
|
614
|
+
if (inputs.template == 'VMP') {
|
|
615
|
+
newPage.drawText('All must operate under', {
|
|
616
|
+
x: 28,
|
|
617
|
+
y: 145,
|
|
618
|
+
size: 10,
|
|
619
|
+
color: rgb(255, 255, 255), // White color
|
|
620
|
+
font: boldFont,
|
|
621
|
+
});
|
|
601
622
|
}
|
|
602
623
|
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
624
|
+
const existingAnnots = newPage.node.lookup(PDFName.of('Annots'));
|
|
625
|
+
let annotationsArray = existingAnnots instanceof PDFArray ? existingAnnots : doc.context.obj([]);
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
const linkAnnotation = doc.context.register(
|
|
629
|
+
doc.context.obj({
|
|
630
|
+
Type: 'Annot',
|
|
631
|
+
Subtype: 'Link',
|
|
632
|
+
Rect: [buttonX, buttonY, buttonX + buttonW, buttonY + buttonH],
|
|
633
|
+
Border: [0, 0, 0],
|
|
634
|
+
A: {
|
|
635
|
+
Type: 'Action',
|
|
636
|
+
S: 'URI',
|
|
637
|
+
URI: PDFString.of((i <= (inputs.buttonLink.length - 1)) ? inputs.buttonLink[i] : inputs.buttonLink[inputs.buttonLink.length - 1]),
|
|
638
|
+
},
|
|
639
|
+
})
|
|
640
|
+
);
|
|
641
|
+
// Append the new annotation to the existing ones
|
|
642
|
+
annotationsArray.push(linkAnnotation);
|
|
643
|
+
// Set the updated annotations array back to the page
|
|
644
|
+
newPage.node.set(PDFName.of('Annots'), annotationsArray);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
if (inputs.QrUrl && inputs.QrUrl.length > 0 && (inputs.QrCodeImage == undefined)) {
|
|
648
|
+
//QR Code
|
|
649
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
650
|
+
const QRCode = require('qrcode');
|
|
651
|
+
const qrDataUrl = (i <= (inputs.QrUrl.length - 1)) ? await QRCode.toDataURL(inputs.QrUrl[i]) : await QRCode.toDataURL(inputs.QrUrl[inputs.QrUrl.length - 1]);
|
|
652
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
653
|
+
const qrImageBytes = await fetch(qrDataUrl).then(res => res.arrayBuffer());
|
|
654
|
+
const qrImage = await doc.embedPng(qrImageBytes);
|
|
655
|
+
newPage.drawImage(qrImage, {
|
|
656
|
+
x: 210,
|
|
657
|
+
y: 93,
|
|
658
|
+
width: 40,
|
|
659
|
+
height: 40,
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
const existingAnnots = newPage.node.lookup(PDFName.of('Annots'));
|
|
663
|
+
let annotationsArray = existingAnnots instanceof PDFArray ? existingAnnots : doc.context.obj([]);
|
|
664
|
+
const linkAnnotation = doc.context.register(
|
|
665
|
+
doc.context.obj({
|
|
666
|
+
Type: 'Annot',
|
|
667
|
+
Subtype: 'Link',
|
|
668
|
+
Rect: [210, 93, 250, 93 + 40],
|
|
669
|
+
Border: [0, 0, 0],
|
|
670
|
+
A: {
|
|
671
|
+
Type: 'Action',
|
|
672
|
+
S: 'URI',
|
|
673
|
+
URI: PDFString.of((i <= (inputs.QrUrl.length - 1)) ? inputs.QrUrl[i] : inputs.QrUrl[inputs.QrUrl.length - 1]),
|
|
674
|
+
},
|
|
675
|
+
})
|
|
676
|
+
);
|
|
677
|
+
// Append the new annotation to the existing ones
|
|
678
|
+
annotationsArray.push(linkAnnotation);
|
|
679
|
+
// Set the updated annotations array back to the page
|
|
680
|
+
newPage.node.set(PDFName.of('Annots'), annotationsArray);
|
|
681
|
+
}
|
|
617
682
|
|
|
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
683
|
|
|
639
|
-
|
|
640
684
|
if (inputs.QrCodeImage && inputs.QrCodeImage.length > 0) {
|
|
641
685
|
const inputQrImageUrl = (i <= (inputs.QrCodeImage.length - 1)) ? inputs.QrCodeImage[i] : inputs.QrCodeImage[inputs.QrCodeImage.length - 1]
|
|
642
686
|
const inputQrBuffer = await this.fetchData(inputQrImageUrl);
|
|
@@ -644,13 +688,13 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
644
688
|
let inputQRembed
|
|
645
689
|
console.log(inputQrImageUrl);
|
|
646
690
|
console.log(inputQrImageUrl.toLowerCase().includes(".png"));
|
|
647
|
-
console.log(inputQrImageUrl.toLowerCase().includes(".jpg")||inputQrImageUrl.toLowerCase().includes(".jpeg"));
|
|
648
|
-
if (inputQrImageUrl.toLowerCase().includes(".png")){
|
|
649
|
-
|
|
650
|
-
|
|
691
|
+
console.log(inputQrImageUrl.toLowerCase().includes(".jpg") || inputQrImageUrl.toLowerCase().includes(".jpeg"));
|
|
692
|
+
if (inputQrImageUrl.toLowerCase().includes(".png")) {
|
|
693
|
+
inputQRembed = await doc.embedPng(inputQrBuffer);
|
|
694
|
+
console.log('embed QR Code image as png');
|
|
651
695
|
}
|
|
652
|
-
|
|
653
|
-
else if (inputQrImageUrl.toLowerCase().includes(".jpg")||inputQrImageUrl.toLowerCase().includes(".jpeg")){
|
|
696
|
+
|
|
697
|
+
else if (inputQrImageUrl.toLowerCase().includes(".jpg") || inputQrImageUrl.toLowerCase().includes(".jpeg")) {
|
|
654
698
|
console.log(inputQrBuffer)
|
|
655
699
|
const dataView = new DataView(inputQrBuffer);
|
|
656
700
|
console.log(dataView)
|
|
@@ -665,11 +709,11 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
665
709
|
console.log('SOI marker not found but forcing to be correct.');
|
|
666
710
|
let fixedArrayBuffer = await this.reencodeImageToArrayBuffer(inputQrBuffer)
|
|
667
711
|
inputQRembed = await doc.embedJpg(fixedArrayBuffer);
|
|
668
|
-
}
|
|
712
|
+
}
|
|
669
713
|
console.log('embed QR Code image as jpg successful');
|
|
670
714
|
}
|
|
671
715
|
|
|
672
|
-
|
|
716
|
+
|
|
673
717
|
newPage.drawImage(inputQRembed, {
|
|
674
718
|
x: 210,
|
|
675
719
|
y: 93,
|
|
@@ -699,7 +743,7 @@ export default class PDFMapGeneratorActivity implements IActivityHandler {
|
|
|
699
743
|
filledPDFs.push(await doc.save());
|
|
700
744
|
|
|
701
745
|
}
|
|
702
|
-
|
|
746
|
+
|
|
703
747
|
const finalPDF = await PDFDocument.create();
|
|
704
748
|
|
|
705
749
|
// Copy pages from all filled PDFs into the final document
|