Click here to Skip to main content
16,021,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to convert PDF file to TEXT file.

This is my code:

String tempFolderPath = Path.GetTempPath();
                       StreamWriter writeTextFile = File.CreateText(tempFolderPath + "content.txt");
            writeTextFile.WriteLine(TransformPdfToText(tempFolderPath + "coalmar100604.pdf"));
            writeTextFile.Close();
 

private static string TransformPdfToText(string SourceFile)
        {
            string content = "";
            PDDocument doc = PDDocument.load(SourceFile);
            PDFTextStripper stripper = new PDFTextStripper();
         
            try
            {
                content = stripper.getText(doc);

                doc.close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                doc.close();
            }
            return content;
        }


the line in bold shows an error:: Object reference not set to an instance of an object.
Posted
Updated 22-Jun-10 1:00am
v2

Shruti Gargate wrote:
writeTextFile.WriteLine(TransformPdfToText(tempFolderPath + "coalmar100604.pdf"));


Put a debug point in the code at the line mentioned above to see if the pdf file exists at the tempFolderPath location.
 
Share this answer
 
Comments
Ankur\m/ 24-Jun-10 9:06am    
Shruti wrote: Yes, the file is present at that location.
(I am deleting the answer which she write to reply you).
When you debug and get to that line, have you checked stripper and doc?

Are either of them null? That would be the only thing that I could think of that would be the problem.
 
Share this answer
 
No i have checked both the stripper and doc both are not null


This is the link of that pdf file. I want to read that values.
I have saved this pdf file on specified location. Can i get the value from the link?

http://tonto.eia.doe.gov/FTPROOT/coal/newsmarket/coalmar100611.pdf">


Thank you in advance.
 
Share this answer
 
Comments
Ankur\m/ 24-Jun-10 9:04am    
Do not add an answer to discuss with a user. The user may not know you have replied to him/her.
Use 'Add Comment' below the user's answer to reply to him. In this way he/she will be notified about your comments.

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