1

I have created a Web application, in that user can do his course by reading the PDF document. For that purpose I need to open that PDF file in new aspx page.

Is there any control to open the PDF? Or Is there any other way to open the PDF?

If you know please help me.

Thanks & Regards, k.kavya

1
  • to open pdf you need to create an anchor tag with target to _new and url to you relative file path. Commented Mar 29, 2013 at 12:25

3 Answers 3

2

You can try this

private void ReadPdfFile()
        {
            string path = @"C:\Swift3D.pdf";
            WebClient client = new WebClient();
            Byte[] buffer =  client.DownloadData(path);



     if (buffer != null)
        {
            Response.ContentType = "application/pdf"; 
            Response.AddHeader("content-length",buffer.Length.ToString()); 
            Response.BinaryWrite(buffer); 
        }

    }

You can find more info at.. http://geekswithblogs.net/azamsharp/archive/2005/09/18/54294.aspx


Now your requirement is that you basically want to read a pdf file you can use a good library for that such as iTextSharp. http://sourceforge.net/projects/itextsharp/

and then use it to extract the data from the pdf into a string

public string ReadPdfFile(string fileName)
{
    StringBuilder text = new StringBuilder();

    if (File.Exists(fileName))
    {
        PdfReader pdfReader = new PdfReader(fileName);

        for (int page = 1; page <= pdfReader.NumberOfPages; page++)
        {
            ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
            string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);

            currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText)));
            text.Append(currentText);
        }
        pdfReader.Close();
    }
    return text.ToString();
}

then display that string into your web page.... It should'nt be difficult now.. Hope it helps.

Sign up to request clarification or add additional context in comments.

11 Comments

Thank you for your reply.. but i need to display the content of pdf in aspx page itself
Though Pdf is not Natively supported by .NET, still you can acheive this by using external libraries such as iTextPdf see my updated answer on how to do this..
I need to open that pdf in page wise.. prev and Next options should be there.. and we need to keep track of page numbers till what page the user completed the course... Please help me in doing this.. I have tried may ways but unable to succed in that...
What you are actually asking is a project in itself. Though i will try to code it all for you but then it won't be possible to post the whole project on stackoverflow.
so in case you want me to code it all for you, you need to tell me the details about your project, and i assume you are from Hyderabad.
|
0

This kind of behavior is handled by the browsers itself, all you need to just flush pdf doc to browser (as suggested by GeekyCoder), and then depends on browser you will see document or will be presented with Save As dialog.

There is no native controls that will display pdf. In case you would like to be sure pdf is always displayed on page you would need to create control for it on your own (or maybe search for free/paid custom one).

Comments

0

Viewing the PDF file in the browser (without download) requires an add-on to the client's browser. Google Chrome, for example, has a built-in PDF viewer and can open files directly, while IE and Firefox require that you install a plug-in (the one that comes with Adobe Reader).

There are two other approaches:

Convert the file to HTML, image, or any other format that can be directly viewed in the browser. This conversion can be on-the-fly using a server-side (written in PHP, Python, ASP, whatever language), or you can just pre-convert all files to a readable one.

The other approach, which is the best, is to use a Flash-based PDF viewer (such as http://flexpaper.devaldi.com/). This is easy, flexible and doesn't require writing server-side code. This approach is used by many Document-sharing sites (e.g. http://www.scribd.com/, http://www.slideshare.net/, http://www.docstoc.com/)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.