@measurequick/measurequick-report-generator 1.2.22 → 1.2.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@measurequick/measurequick-report-generator",
3
- "version": "1.2.22",
3
+ "version": "1.2.24",
4
4
  "description": "Generates PDF documents for various MeasureQuick applications.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -23,46 +23,49 @@ export async function getReport(payload) {
23
23
  // Process All Photos
24
24
  let previousPhotoCollectionName;
25
25
  let photoCollectionNames = ["project", "equipment", "site", "customer"];
26
+ let docIndex = 0;
26
27
  for (let pcnIndex = 0; pcnIndex < photoCollectionNames.length; pcnIndex++) { // Iterate over all 4 photo photo collections
27
28
  let photoCollectionName = photoCollectionNames[pcnIndex];
28
29
  let photoCollection = payload.photos[photoCollectionName];
29
30
  let photoSectionKeys = Object.keys(photoCollection);
30
31
  if (!photoSectionKeys || photoSectionKeys.length == 0) break;
32
+ docs[docIndex] = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
33
+ forms[docIndex] = docs[docIndex].getForm();
34
+ forms[docIndex].getButton("FullWidthLogo").setImage(await docs[docIndex].embedPng(mqLogoBytes));
35
+ forms[docIndex].getTextField("Header").setText(`${util.capitalizeFirstLetter(photoCollectionName)} Photos`);
31
36
  let photoPosition = 1;
32
- let doc = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
33
- let form = doc.getForm();
34
- docs.push(doc);
35
- forms.push(form);
36
- form.getButton("FullWidthLogo").setImage(await doc.embedPng(mqLogoBytes));
37
- form.getTextField("Header").setText(`${util.capitalizeFirstLetter(photoCollectionName)} Photos`);
38
37
  for (let pskIndex = 0; pskIndex < photoSectionKeys.length; pskIndex++) { // Iterate over X user-defined photo sections within each photo collection
39
38
  let photoSectionKey = photoSectionKeys[pskIndex];
40
39
  let photoSection = photoCollection[photoSectionKey];
40
+ console.log(`Starting Section ${photoSection.name}`);
41
41
  let photos = photoSection.photos;
42
42
  if (!photos || photos.length == 0) break;
43
43
  for (let pIndex = 1; pIndex <= photos.length; pIndex++) { // Iterate over X user-defined photos within each photo section
44
44
  let photo = photos[pIndex-1];
45
45
  if (photoPosition > maxPhotosPerPage) { // Need a new page
46
46
  photoPosition = 1;
47
- doc = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
48
- form = doc.getForm();
49
- docs.push(doc);
50
- forms.push(form);
51
- form.getButton("FullWidthLogo").setImage(await doc.embedPng(mqLogoBytes));
52
- form.getTextField("Header").setText(`${util.capitalizeFirstLetter(photoCollectionName)} Photos`);
47
+ docIndex++;
48
+ docs[docIndex] = await PDFDocument.load(util._base64ToArrayBuffer(page.base64));
49
+ forms[docIndex] = docs[docIndex].getForm();
50
+ forms[docIndex].getButton("FullWidthLogo").setImage(await docs[docIndex].embedPng(mqLogoBytes));
51
+ forms[docIndex].getTextField("Header").setText(`${util.capitalizeFirstLetter(photoCollectionName)} Photos`);
53
52
  }
54
53
  let imageToSet;
55
- if (photo.base64.includes("image/jpeg")) imageToSet = await doc.embedJpg(util._base64ToArrayBuffer(photo.base64));
56
- else if (photo.base64.includes("image/png")) imageToSet = await doc.embedPng(util._base64ToArrayBuffer(photo.base64));
57
- if (imageToSet) form.getButton(`photo${pSize}${pIndex}`).setImage(imageToSet);
54
+ if (photo.base64.includes("image/jpeg")) imageToSet = await docs[docIndex].embedJpg(util._base64ToArrayBuffer(photo.base64));
55
+ else if (photo.base64.includes("image/png")) imageToSet = await docs[docIndex].embedPng(util._base64ToArrayBuffer(photo.base64));
56
+ if (imageToSet) {
57
+ console.log(`Printing ${photo.tag} in Position #${photoPosition} on Page #${docIndex+1}`);
58
+ forms[docIndex].getButton(`photo${pSize}${photoPosition}`).setImage(imageToSet);
59
+ }
58
60
  let photoSubText = photoSection.name;
59
61
  let isFirstPhotoOfSection = previousPhotoCollectionName == photoCollectionName;
60
62
  if (isFirstPhotoOfSection && photoSection.hasNotes) photoSubText += `: ${photoSection.notes}`;
61
- form.getTextField(`Notes${pIndex}`).setText(`${photoSubText}`);
63
+ forms[docIndex].getTextField(`Notes${photoPosition}`).setText(`${photoSubText}`);
62
64
  photoPosition++;
63
65
  previousPhotoCollectionName = photoCollectionName;
64
66
  }
65
67
  }
68
+ docIndex++;
66
69
  }
67
70
 
68
71
  // Prepare Deliverable