i




 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pdf to text conversion in asp.net c#
12-12-2012, 09:02 PM
Post: #1
pdf to text conversion in asp.net c#
I created a sample web application to convert any given pdf document to text. I got free utility pdftotext from xpdf to perform this action. The positive thing about this utility is that it extract the pdf text and save into newly create text file without writing any extra code.

This utility required following command to execute to Convert the URL into PDF file.
Code:
pdftotext file.pdf

here is some documentation about pdftotext
to upload the pdf file to executable directory (the text file will also save on same location)
Code:
private void Upload_PDF_File(string filename)
    {
        FU_Pdf.PostedFile.SaveAs(GetFilePath() +"\\"+ filename.Trim());
    }

to create the above mentioned command, i wrote a method Construct_Command(...)
Code:
private void Construct_Command(string PDFPath)
    {
        string str_Command = string.Empty;
        string PDF_Server_Path = GetFilePath() + "\\" + PDFPath;
        str_Command = "pdftotext " + PDF_Server_Path;

        //Execute command on pdftotext
        Execute_Command(str_Command);
        GenerateHyperLink(PDFPath.Replace(".pdf", ".txt"));
    }

To execute the above command on executable file, i wrote following method.
Code:
public void Execute_Command(string str_Command)
    {
        try
        {
            ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + GetFilePath() + "\\" + str_Command);
            procStartInfo.RedirectStandardOutput = true;
            procStartInfo.UseShellExecute = false;
            procStartInfo.CreateNoWindow = true;
            Process proc = new Process();
            proc.StartInfo = procStartInfo;
            proc.Start();
            proc.WaitForExit();
        }
        catch (Exception objException)
        {
            // Log the exception
        }
    }

Live Demo:
http://converter.dotnetauthor.com/index....onversion/

Desktop Version
I will post the desktop version very soon...

the complete code is attached. please feel free to ask questions.
I also attached the pdftotext documentation.




Attached File(s)
.zip  PdfToText.zip (Size: 481.32 KB / Downloads: 121)
.txt  pdftotext.txt (Size: 4.08 KB / Downloads: 68)

[Image: 2604595733.png]
Quote


Possibly Related Threads...
Thread: Author Replies Views: Last Post
  PDF to Image Conversion in ASP.NET magnum_2007 7 4,293 07-25-2014 09:13 AM
Last Post: alxe_2014
  Html to Pdf conversion in asp.net c# nisar87 7 40,001 06-17-2014 06:31 AM
Last Post: dev_chirs
  Html to pdf conversion in c# nisar87 11 18,597 05-15-2014 07:10 AM
Last Post: dev_chirs
  pdf to html conversion in asp.net c# nisar87 6 3,636 12-16-2013 07:16 AM
Last Post: felin
  pdf to image conversion in asp.net c# nisar87 8 23,057 11-25-2013 09:37 AM
Last Post: felin



User(s) browsing this thread: 1 Guest(s)