[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

PDF to Excel C#, ASP.NET

Posted on 2008-09-29
12
Medium Priority
?
2,966 Views
Last Modified: 2013-12-17
I have a pdf file that contains a table. I need to be able to read this data into my C# ASP.NET application. I was thinking of first converting it to an excel file and then using the interlop class to open and read the excel file.

Does anyone how know to successfully read an PDF file?

Many thanks.
0
Comment
Question by:copyPasteGhost
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 14

Expert Comment

by:CyrexCore2k
ID: 22599673
That is going to be extremely hairy and error prone. If there is any other option at all I suggest you consider it before embarking on a design like this. Perhaps if you share the details of your project I might be able to suggest something a bit less... brutal?
0
 
LVL 13

Author Comment

by:copyPasteGhost
ID: 22599791
I argee...This is going to extremely hardcore....Alright basically we are sent by email a document from the post office in (pdf). I need to extrapulate the data from the pdf (tracking number, price) and then scrap the post office site passing the tracking number in the url string to find out when the package arrived and then write the results to an excel file, then email it to the tracking department.

That's pretty much it.
0
 
LVL 14

Expert Comment

by:CyrexCore2k
ID: 22599830
I would /think/ the post office would have an option to email you plain text emails. I'd be very surprised if they didn't. Or have you already explored that possibility?
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 13

Author Comment

by:copyPasteGhost
ID: 22599855
the thing is they don't really email us the document. they email us an alert letting us know the doc is ready and we go download on their site. (in pdf format) we are actually trying to get the post office to give it to us in excel. Would plain text be better? If so why?
0
 
LVL 14

Expert Comment

by:CyrexCore2k
ID: 22599888
well plain text is always easiest to parse.

hmmm... still, it seems odd that they wouldn't have equivalent information in plain text format readily available on the site.
0
 
LVL 13

Author Comment

by:copyPasteGhost
ID: 22599901
maybe I didn't look hard enough. let me check and then get back to you.
0
 
LVL 13

Author Comment

by:copyPasteGhost
ID: 22600035
nope. only pdf.
0
 
LVL 14

Expert Comment

by:CyrexCore2k
ID: 22600042
You might try calling them too. Ask them where you should view your bill if you're blind. I'm assuming you're talking about the USPS which is required to maintain 508 compliance which means they should have resources for the blind. Since they can't rely on Adobe Reader properly maintaining compliance they should have a text version available that can be read by any text based browser (combined with a speech generator this is what the blind normally use).
0
 
LVL 13

Author Comment

by:copyPasteGhost
ID: 22600102
I'm actually in canada. so it's Canada Post. But I'm sure they have something similar...

I found a service called zamzar they will convert a pdf into text.

they give me a file that looks like this:

                7146410002759095              EX/CA J7E         A1A 5S4            1   9.47  5,19,20       3        5          15.90             3.65             19.55
                7146410002760091              EX/CA J7E         M3A 1S6            1   4.27   19,20        2        5           5.88             0.65              6.53
                7146410002761098              EX/CA J7E         M3C 3N4            1   0.33   19,20        2        5           4.21             0.46              4.67
                7146410002762095              EX/CA J7E         T0C 0T0            1   1.00   19,20        2        5           9.25             1.02             10.27
                7146410002763092              EX/CA J7E         E2M 1J8            1   0.33   19,20        3        5           6.18             0.68              6.86
                7146410002764099              EX/CA J7E         G0A 1A0            1   1.00   19,20        2        4           6.38             0.70              7.08
                7146410002765096              EX/CA J7E         K0K 1X0            1   0.58   19,20        2        5           5.79             0.64              6.43
                7146410002767090              EX/CA J7E         H7N 4X5            1   2.37   19,20        2        4           4.46             0.49              4.95



I'm interested in the 9th column. the one starting with 15.90. then 5.88.....

How can I parse that?

Thanks.
0
 
LVL 14

Accepted Solution

by:
CyrexCore2k earned 2000 total points
ID: 22600215
Assuming those are spaces and not tabs you can open the file and read each line into a string. Then use

Eater(ref myLine, 8);
string Value = Eater(ref myLine, 1);

For each one of the lines and you should be able to grab the values.
        private static string Eater(ref string record, int elements)
        { return Eater(ref record, elements, " "); }
        private static string Eater(ref string record, int elements, string separator)
        {
            int start = 0;
            int separatorat = record.IndexOf(separator, start);
            StringBuilder sb = new StringBuilder();
 
            if(separatorat == -1)
            {
                sb.Append(record);
                record = "";
                return sb.ToString();
            }
 
            while (elements > 0 & separatorat > -1)
            {
                elements--;
                if (separatorat - start > 0)
                {
                    sb.Append(record.Substring(start, separatorat - start));
                    start = separatorat;
                }
                while (record.Substring(start, 1) == separator & start + 1 < record.Length)
                    start++;
                record = record.Substring(start);
                start = 0;
                separatorat = record.IndexOf(separator, start);
            }
            return sb.ToString();
        }

Open in new window

0
 
LVL 13

Author Comment

by:copyPasteGhost
ID: 22605725
I see you are using the ref keyword....

what does that do?

thanks
0
 
LVL 14

Expert Comment

by:CyrexCore2k
ID: 22610597
If you pass an object using the ref keyword to a function and then change the value of that parameter from inside the function the original value will also change. Refer to the example below.

I use it in this case because I want the eater function to "eat" the portion of the string that it's parsed as well as pass back a value to me. Since I can't get multiple return values, this method works quite nicely.
void UseRef(ref string somevalue)
{
   somevalue = "Hello World!";
}
 
void SomeFunction()
{
   string myvalue = "Hello.";
   // Message box will be "Hello."
   System.Windows.Forms.MessageBox.Show(myvalue);
   // Note you use the ref keyword here as well.
   UseRef(ref myvalue);
   // Message box will be "Hello World!"
   System.Windows.Forms.MessageBox.Show(myvalue);
}

Open in new window

0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question