Link Search Menu Expand Document

Parsing and reading data from Airline Tickets - Delphi

Document Parser SDK sample in Delphi demonstrating ‘Parsing and reading data from Airline Tickets’

ParsingDataFromAirlineTickets.dpr
program ParsingDataFromAirlineTickets;

//*******************************************************************************************//
//                                                                                           //
// Download Free Evaluation Version From: https://bytescout.com/download/web-installer       //
//                                                                                           //
// Also available as Web API! Get Your Free API Key: https://app.pdf.co/signup               //
//                                                                                           //
// Copyright � 2017-2020 ByteScout, Inc. All rights reserved.                                //
// https://www.bytescout.com                                                                 //
// https://pdf.co                                                                            //
//                                                                                           //
//*******************************************************************************************//

{$APPTYPE CONSOLE}

uses
  SysUtils,
  ActiveX,
  ByteScout_DocumentParser_TLB in 'C:\Program Files\Borland\BDS\4.0\Imports\ByteScout_DocumentParser_TLB.pas';

var
  document_parser: _DocumentParser;
  json: string;
  yaml: string;
  xml: string;

const
  INPUT_DOCUMENT: string = 'SampleTicket.pdf';
  TEMPLATE_DOCUMENT: string = 'SampleTicket.yml';

begin
  // disable floating point exception to conform to .NET floating point operations behavior.
  System.Set8087CW($133F);
  
  // required for console applications, initializes ActiveX support
  CoInitialize(nil);

  // create and activate DocumentParser instance
  document_parser := CoDocumentParser.Create();
  document_parser.RegistrationName := 'demo';
  document_parser.RegistrationKey := 'demo';

  document_parser.AddTemplate(TEMPLATE_DOCUMENT);

  // parse document data in JSON format
  json := document_parser.ParseDocument_4(INPUT_DOCUMENT, OutputFormat_JSON, false);

  // display parsed data in console
  WriteLn('Parsing results in JSON format:');
  WriteLn('');
  WriteLn(json);

  WriteLn('=========================');

  // parse document data in YAML format
  yaml := document_parser.ParseDocument_4(INPUT_DOCUMENT, OutputFormat_YAML, false);

  // display parsed data in console
  WriteLn('Parsing results in YAML format:');
  WriteLn('');
  WriteLn(yaml);

  WriteLn('=========================');

  // parse document data in XML format
  xml := document_parser.ParseDocument_4(INPUT_DOCUMENT, OutputFormat_XML, false);
  // display parsed data in console
  WriteLn('Parsing results in XML format:');
  WriteLn('');
  WriteLn(xml);

  document_parser.Dispose();

  CoUninitialize();
end.

SampleTicket.yml
templateName: MakeMyTrip Booking
templateVersion: 4
templatePriority: 0
detectionRules:
  keywords:
  - MakeMyTrip
  - Eticket-Dom-Flight
objects:
- name: BookingNo
  objectType: field
  fieldProperties:
    fieldType: rectangle
    rectangle:
    - 198.75
    - 85.625
    - 96.875
    - 12.500001
    pageIndex: 0
- name: BookingDate
  objectType: field
  fieldProperties:
    fieldType: rectangle
    dataType: date
    rectangle:
    - 133.125
    - 97.5000076
    - 78.75
    - 12.500001
    pageIndex: 0
- name: DepartureFrom
  objectType: field
  fieldProperties:
    fieldType: rectangle
    rectangle:
    - 153
    - 176
    - 77
    - 8.5
    pageIndex: 0
- name: ArrivalTo
  objectType: field
  fieldProperties:
    fieldType: rectangle
    rectangle:
    - 285
    - 176
    - 84
    - 8.5
    pageIndex: 0
- name: DepartureAt
  objectType: field
  fieldProperties:
    fieldType: rectangle
    dataType: date
    rectangle:
    - 153.75
    - 187.5
    - 123.75
    - 10.625
    pageIndex: 0
- name: ArrivalAt
  objectType: field
  fieldProperties:
    fieldType: rectangle
    dataType: date
    rectangle:
    - 288.125
    - 186.875
    - 125.625008
    - 11.25
    pageIndex: 0
- name: FlightType
  objectType: field
  fieldProperties:
    fieldType: rectangle
    rectangle:
    - 433.5
    - 159.5
    - 68
    - 10.5
    pageIndex: 0
- name: FlightDuration
  objectType: field
  fieldProperties:
    fieldType: rectangle
    rectangle:
    - 474.375031
    - 170.625
    - 30.0000019
    - 10
    pageIndex: 0
- name: CabinType
  objectType: field
  fieldProperties:
    fieldType: rectangle
    rectangle:
    - 463.125031
    - 194.375015
    - 51.25
    - 10
    pageIndex: 0
- name: PassengerName
  objectType: field
  fieldProperties:
    fieldType: rectangle
    rectangle:
    - 85
    - 238.125
    - 93.125
    - 14.375
    pageIndex: 0
- name: PassengerType
  objectType: field
  fieldProperties:
    fieldType: rectangle
    rectangle:
    - 229.375015
    - 238.125
    - 31.25
    - 13.75
    pageIndex: 0
- name: AirlinePNR
  objectType: field
  fieldProperties:
    fieldType: rectangle
    rectangle:
    - 375
    - 240.000015
    - 46.25
    - 13.75
    pageIndex: 0


Download Source Code (.zip)

Return to the previous page Explore Document Parser SDK


Copyright © 2016 - 2021 ByteScout