Parsing and reading data from Airline Tickets - C#
Document Parser SDK sample in C# demonstrating ‘Parsing and reading data from Airline Tickets’
Program.cs
using System;
using ByteScout.DocumentParser;
// This example demonstrates document data parsing to JSON, YAML and XML formats.
namespace GeneralExample
{
class Program
{
static void Main(string[] args)
{
string templateDocument = @".\SampleTicket.yml";
string inputDocument = @".\SampleTicket.pdf";
// Create DocumentParser instance
using (DocumentParser documentParser = new DocumentParser("demo", "demo"))
{
// Add template format
documentParser.AddTemplate(templateDocument);
// Parse document data in JSON format
string jsonString = documentParser.ParseDocument(inputDocument, OutputFormat.JSON);
// Display parsed data in console
Console.WriteLine("Parsing results in JSON format:");
Console.WriteLine();
Console.WriteLine(jsonString);
Console.WriteLine("\n\n=========================\n\n");
// Parse document data in YAML format
string yamlString = documentParser.ParseDocument(inputDocument, OutputFormat.YAML);
// Display parsed data in console
Console.WriteLine("Parsing results in YAML format:");
Console.WriteLine();
Console.WriteLine(yamlString);
Console.WriteLine("\n\n=========================\n\n");
// Parse document data in XML format
string xmlString = documentParser.ParseDocument(inputDocument, OutputFormat.XML);
// Display parsed data in console
Console.WriteLine("Parsing results in XML format:");
Console.WriteLine();
Console.WriteLine(xmlString);
}
Console.WriteLine();
Console.WriteLine("Press any key to continue...");
Console.ReadLine();
}
}
}
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