469,365 Members | 2,030 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,365 developers. It's quick & easy.

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 ...
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

5 11400
Frinavale
9,735 Expert Mod 8TB
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
465 Expert Mod 256MB
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
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
9,735 Expert Mod 8TB
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
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.

Similar topics

1 post views Thread by Fabrizio | last post: by
1 post views Thread by Jerry Tovar | last post: by
9 posts views Thread by Steve Peterson | last post: by
2 posts views Thread by Ravi | last post: by
2 posts views Thread by paul.gibson | last post: by
reply views Thread by Alain Quesnel | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.