how to show pdf file on aspx page without save option?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • karimkhan
    New Member
    • Jan 2011
    • 54

    how to show pdf file on aspx page without save option?

    I m putting link to pdf file , on click which should open in same or other page and that pdf file should be visible on the page, how to do this,

    on givin link of pdf file it's directly showing download dialouge ...
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    If the user has a plugin installed in their browser, the PDF file will be displayed in the browser. Otherwise, the user will be prompted to download the PDF file so that they can choose a program installed on their computer that can open the file.

    If you want to display the PDF in another page, simply set the target of the hyperlink to "_blank"... like this:
    Code:
    <a href="urlToPDF" target="_blank">PDF</a>
    If you're using an ASP.NET HyperLink control, your code would look like:
    Code:
    <asp:HyperLink id="hyperlink1" 
                   NavigateUrl="urlToPDF"
                   Text="PDF"
                   Target="_blank"
                   runat="server"/>
    If you want it to be displayed within the same page, then you don't need to specify a target. This will replace the content being displayed in the browser with the PDF document.

    If you want the PDF document to be displayed within the content of your page, then consider using an <iframe /> to do so.

    -Frinny

    Comment

    • PsychoCoder
      Recognized Expert Contributor
      • Jul 2010
      • 465

      #3
      Here's an option that should work for what you're trying to do:

      Code:
      private void ReadPdfFile()
      {
          var pdfPath = @"C:\YourPDFFile.pdf";
          var client = new WebClient();
          var buffer = client.DownloadData(pdfPath);
      
          if (buffer == null) 
              return;
      
          Response.ContentType = "application/pdf";
          Response.AddHeader("content-length", buffer.Length.ToString());
          Response.BinaryWrite(buffer);
      }
      Hope that helps

      Comment

      • raghurocks
        New Member
        • May 2012
        • 46

        #4
        if you use System.Diagnost ics.Process.Sta rt(FilePath) then that file will be opend automatically.. ....i think this will solve ur problem..

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          How is System.Diagnost ics.Process.Sta rt(FilePath) supposed to open the file in the browser?

          When a web browser downloads content it has to determine what to do with that content. If the content is HTML, then it displays the HTML webpage. If the content is a PDF document, it checks to see if it has a plugin installed that can open and display this content...and if there is no plugin installed that can handle the content that it's downloaded, it asks the user what to do with it (save it and open the document with a program that knows what to do with it).

          -Frinny

          Comment

          • karimkhan
            New Member
            • Jan 2011
            • 54

            #6
            Dear it is promting dialoge to download the file I cant let pdf to view in browser thru this..

            Comment

            Working...