File indexing completed on 2024-12-29 04:51:03
0001 /* 0002 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 function extractColumn(page, offset) { 0008 var text = page.textInRect(offset, 0, offset + 0.5, 1); 0009 if (!text.match(/FLIGHT \d+/)) 0010 return null; 0011 0012 var res = JsonLd.newFlightReservation(); 0013 var images = page.imagesInRect(offset, 0, offset + 0.5, 1); 0014 for (var i = 0; i < images.length; ++i) { 0015 if (images[i].width < 300 && images[i].height < images[i].width) { 0016 res.reservedTicket.ticketToken = "aztecCode:" + Barcode.decodePdf417(images[i]); 0017 break; 0018 } 0019 } 0020 0021 var dep = text.match(/Departure time.*\n(\d{1,2} \w+ \d{4})\s+(\d{1,2}:\d{2})/); 0022 if (dep) 0023 res.reservationFor.departureTime = JsonLd.toDateTime(dep[1] + " " + dep[2], "dd MMMM yyyy hh:mm", "en"); 0024 var arr = text.match(/Arrival time.*\n(\d{1,2} \w+ \d{4})\s+(\d{1,2}:\d{2})/); 0025 if (arr) 0026 res.reservationFor.arrivalTime = JsonLd.toDateTime(arr[1] + " " + arr[2], "dd MMMM yyyy hh:mm", "en"); 0027 0028 return res; 0029 } 0030 0031 function main(pdf) { 0032 var result = new Array(); 0033 0034 // each page has up to two columns, each describing one flight leg 0035 for (var i = 0; i < pdf.pageCount; ++i) { 0036 var page = pdf.pages[i]; 0037 result.push(extractColumn(page, 0)); 0038 result.push(extractColumn(page, 0.5)); 0039 } 0040 0041 return result; 0042 }