public static void ParseDTCs(string[] args) { string pdf = @"C:\Users\steveb\Desktop\Logger\Simos85.pdf"; PdfReader reader = new PdfReader(pdf);// @"C:\Users\steve\Source\Repos\fr-pdf-parser\FR_PDF_PARSER\Siemens 3.0T Audi S4, S5, A6, Q7.pdf"); List <DTC> dtcs = new List <DTC>(); DTC current = null; for (int page = 5383; page <= reader.NumberOfPages; ++page) { string pageText = PdfTextExtractor.GetTextFromPage(reader, page); string[] lines = pageText.Split(new char[] { (char)0x0A }, StringSplitOptions.None); for (int i = 0; i < lines.Length; ++i) { string line = lines[i].Trim(); if (line.StartsWith("Symptom based diagnostics")) { page = 999999999; break; } else if (line.StartsWith("Designed by")) { //end of page break; } else if (line.StartsWith("Transmittal, reproduction") || line.StartsWith("as well as utilisation") || line.StartsWith("without express") || line.StartsWith("for payment of damages") || line.StartsWith("of a utility model") || line.StartsWith("Chapter Part") || line.StartsWith("Table of failures")) { //start of page continue; } string[] values = line.Split(' '); DTC start = DTC.GetStartDTC(values); if (start != null) { if (current != null && current.Description.Length > 0) { current.Description = current.Description.Substring(0, current.Description.Length - 1); } dtcs.Add(start); int startIndex = 0; if (DTC.IsErrorName(values[0]) && DTC.IsErrorName(values[1])) { start.GlobalError = values[0]; start.ErrorLocation = values[1]; start.Description = ""; startIndex = 2; } else if (DTC.IsErrorName(values[0])) { start.GlobalError = current.GlobalError; start.ErrorLocation = values[0]; start.Description = ""; startIndex = 1; } else { start.GlobalError = current.GlobalError; start.ErrorLocation = current.ErrorLocation; start.Description = ""; startIndex = 0; } for (int j = startIndex; j < start.DFCIndex - 1; ++j) { start.Description += values[j] + " "; } current = start; } else if (current != null) { int startIndex = 0; //DO STUFF TO ADD IN DESCRIPTION if (values.Length > 2 && DTC.IsErrorName(values[0]) && DTC.IsErrorName(values[1])) { current.GlobalError += values[0]; current.ErrorLocation += values[1]; startIndex = 2; } else if (values.Length > 1 && DTC.IsErrorName(values[0])) { startIndex = 1; current.GlobalError += values[0]; } else { startIndex = 0; } for (int j = startIndex; j < values.Length; ++j) { current.Description += values[j] + " "; } } } } XmlSerializer ser = new XmlSerializer(typeof(List <DTC>)); using (FileStream fs = new FileStream(@"c:\temp\parsedDTCS.xml", FileMode.Create)) { ser.Serialize(fs, dtcs); } }