By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,950 Members | 1,019 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,950 IT Pros & Developers. It's quick & easy.

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

P: 54
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 ...
Jun 18 '12 #1

✓ answered by Frinavale

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:
Expand|Select|Wrap|Line Numbers
  1. <a href="urlToPDF" target="_blank">PDF</a>
If you're using an ASP.NET HyperLink control, your code would look like:
Expand|Select|Wrap|Line Numbers
  1. <asp:HyperLink id="hyperlink1" 
  2.                NavigateUrl="urlToPDF"
  3.                Text="PDF"
  4.                Target="_blank"
  5.                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

Share this Question
Share on Google+
5 Replies


Frinavale
Expert Mod 5K+
P: 9,731
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:
Expand|Select|Wrap|Line Numbers
  1. <a href="urlToPDF" target="_blank">PDF</a>
If you're using an ASP.NET HyperLink control, your code would look like:
Expand|Select|Wrap|Line Numbers
  1. <asp:HyperLink id="hyperlink1" 
  2.                NavigateUrl="urlToPDF"
  3.                Text="PDF"
  4.                Target="_blank"
  5.                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
Jun 18 '12 #2

PsychoCoder
Expert Mod 100+
P: 465
Here's an option that should work for what you're trying to do:

Expand|Select|Wrap|Line Numbers
  1. private void ReadPdfFile()
  2. {
  3.     var pdfPath = @"C:\YourPDFFile.pdf";
  4.     var client = new WebClient();
  5.     var buffer = client.DownloadData(pdfPath);
  6.  
  7.     if (buffer == null) 
  8.         return;
  9.  
  10.     Response.ContentType = "application/pdf";
  11.     Response.AddHeader("content-length", buffer.Length.ToString());
  12.     Response.BinaryWrite(buffer);
  13. }
Hope that helps
Jun 19 '12 #3

P: 46
if you use System.Diagnostics.Process.Start(FilePath) then that file will be opend automatically......i think this will solve ur problem..
Jun 19 '12 #4

Frinavale
Expert Mod 5K+
P: 9,731
How is System.Diagnostics.Process.Start(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
Jun 19 '12 #5

P: 54
Dear it is promting dialoge to download the file I cant let pdf to view in browser thru this..
Jun 28 '12 #6

Post your reply

Sign in to post your reply or Sign up for a free account.