Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
So at the moment, I have a PDF I am trying to parse


8:45 9:15 HMI IHMI1 HMI 12:45 12:45 0 MTWRFS MTWRFS
Transit 
CarrierSCAC: BPUS Stop Number:
CYT-HMI-S-004 1 Release Type: AUTO
Route Name:
Days to 
Pick-up Delivery 
Final 
Order Due @ 
Frequency: Frequency:
Carrier Departure Plant Destination Dock Code Initial Dest Location
Carrier Arrival Final Location
Initial Arrival
9:45 10:15 HMI IHMI1 HMI 13:45 13:45 0 MTWRFS MTWRFS
Transit 
CYT-HMI-S-005 CarrierSCAC: BPUS Stop Number:1 Release Type: AUTO
Route Name:
Days to 
Pick-up Delivery 
Final 
Order Due @ 
Frequency: Frequency:
Location
Carrier Arrival Carrier Departure Plant Destination Dock Code Initial Dest Final Location
Initial Arrival
10:45 11:15 HMI IHMI1 HMI 14:45 14:45 0 MTWRFS MTWRFS
Transit 
CYT-MAP-S-001 CarrierSCAC: ONEW Stop Number:1 Release Type: AUTO
Route Name:
Days to 
Pick-up Delivery 
Final 
Order Due @ 
Frequency: Frequency:
Location
Carrier Arrival Carrier Departure Plant Destination Dock Code Initial Dest Final Location
Initial Arrival
13:45 14:15 MAP MAP1 MAP 15:15 15:15 0 MTWRFS MTWRFS
Transit 
CarrierSCAC: ONEW Stop Number:
CYT-MAP-S-002 1 Release Type: AUTO
Route Name:



Code I am currently using


<pre>public static void ReadPDF()
        {
            StringBuilder text = new StringBuilder();
            using (PdfReader reader = new PdfReader(@"C:\Users\bwhitt.1.3864\Desktop\CEVA.pdf"))
            {
                for (int i = 1; i <= reader.NumberOfPages; i++)
                {
                    text.Append(PdfTextExtractor.GetTextFromPage(reader, i));
                    Debug.Print(text.ToString());
                }
            }
           
        }




My desired output would be
CYT-HMI-S-004 8:45 9:15 HMI IHMI1 HMI 12:45 12:45 0 MTWRFS MTWRFS

CYT-HMI-S-005  9:45 10:15 HMI IHMI1 HMI 13:45 13:45 0 MTWRFS MTWRFS


CYT-MAP-S-001 10:45 11:15 HMI IHMI1 HMI 14:45 14:45 0 MTWRFS MTWRFS


CYT-MAP-S-002 1  13:45 14:15 MAP MAP1 MAP 15:15 15:15 0 MTWRFS MTWRFS



this is how I would like the data to be shown route number then the line after "inital arrival" How would I do this?

What I have tried:

just tried to extract the pdf and read the lines. That's all I am able to do,
Posted
Updated 10-Jun-20 23:01pm

1 solution

I already gave you a suggestion in your previous question on this subject. You need to read each line looking for patterns. When you find a line that contains "Initial Arrival", you know that the next line contains the data you are looking for.
 
Share this answer
 
Comments
Knowledged 11-Jun-20 10:19am    
Okay so I have it parsed to be like this:

10:15 11:00 HMI IOSL1 OSL 17:15 17:15 0 MTWRFS MTWRFS
9:00 9:45 PMC YMEI2H DSC 12:45 20:30 0 M M
7:00 7:45 ELP TOSCC1 OSE 12:45 12:45 0 MTWRFS MTWRFS
16:30 17:15 MAP AMMC1 MMC 20:30 20:30 0 MTWRFS MTWRFS
6:30 7:00 ELP ELP1 ELP 8:15 8:15 0 MTWRFS MTWRFS
9:30 10:00 ELP ELP1 ELP 11:15 11:15 0 MTWRFS MTWRFS
10:45 11:15 ELP ELP1 ELP 12:30 12:30 0 MTWRFS MTWRFS
12:15 12:45 ELP ELP1 ELP 14:00 14:00 0 MTWRFS MTWRFS
12:30 13:00 ELP ELP1 ELP 14:15 14:15 0 MTWRFS MTWRFS
13:00 13:30 ELP ELP1 ELP 14:45 14:45 0 MTWRFS MTWRFS
13:30 14:00 ELP ELP1 ELP 15:15 15:15 0 MTWRFS MTWRFS
14:45 15:15 ELP ELP1 ELP 16:30 16:30 0 MTWRFS MTWRFS
17:45 18:15 ELP ELP1 ELP 19:30 19:30 0 MTWRFS MTWRFS
18:15 18:45 ELP ELP1 ELP 20:00 20:00 0 MTWRFS MTWRFS
6:30 7:00 HMI IHMI1 HMI 10:30 10:30 0 MTWRFS MTWRFS
6:45 7:15 HMI IHMI1 HMI 10:45 10:45 0 MTWRFS MTWRFS
8:45 9:15 HMI IHMI1 HMI 12:45 12:45 0 MTWRFS MTWRFS
9:45 10:15 HMI IHMI1 HMI 13:45 13:45 0 MTWRFS MTWRFS
10:45 11:15 HMI IHMI1 HMI 14:45 14:45 0 MTWRFS MTWRFS
13:45 14:15 MAP MAP1 MAP 15:15 15:15 0 MTWRFS MTWRFS
16:45 17:15 MAP MAP1 MAP 18:15 18:15 0 MTWRFS MTWRFS


I found this article: https://sa.ndeep.me/post/programatically-add-rows-in-a-wpf-datagrid/

So what I am trying to do now is separate and add to datagrid like this

13:45 14:15 MAP MAP1 MAP 15:15 15:15 0 MTWRFS MTWRFS


Routes.Collection.Add(new Route { TimeArrived = "13:45", TimeDeparted = "14:15", ShipLocation = "MAP" ...});


and so on, I hope this makes sense.
Richard MacCutchan 11-Jun-20 10:26am    
What is the problem?
Knowledged 11-Jun-20 10:27am    
How am I able to add those into the collection from strings
Richard MacCutchan 11-Jun-20 10:31am    
Like I told you before. Split the string into its separate parts and add each item to successive cells in the DataGridView row. Given that you have created a MVVM project I would expect you to find such basic questions easy.
Knowledged 11-Jun-20 10:33am    
you're saying exactly what i'm saying. I know what I want it to do. I am asking for help in doing the task...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900