Last post Sep 03, 2011 02:27 PM by siteslayer
Aug 25, 2006 08:49 PM|azayas48|LINK
Hi, I need to display a pdf document inside a web form. I know how to do so using an hyperlink control (NavigateUrl property), but in this case I need to display the pdf as a result of an internal process, not the click of a link by
the user. There is any way to do so? Thanks in advance.
Aug 31, 2006 04:11 PM|Javier Luna|LINK
That will be very slow. I don't recommend it. You would to use open PDF file in new window.
Oct 02, 2006 01:01 PM|priyap|LINK
I had a similar requirement. Adobe comes with a free Active X dll (even for Reader) called AcroPDF.dll. You should be able to find this under Program Files\Adobe\Reader\active X.
In my web application (.NET 1.1), I added a new COM control reference in the toolbar to this dll and placed it on the web form. You can then pass the PDf file name to the SRC property.
<PARAM NAME="SRC" VALUE="<%= Me.strPAth %>"
Where Me.strPAth is a module level string int he code behind page.
Oct 06, 2006 06:48 PM|Haissam|LINK
in order to display a pdf file inside a webform u have to do the following after certain processing
string filePath = ur file path on the server
Response.contentType = "application/pdf";
Jan 14, 2007 05:52 PM|Blazingfun|LINK
This works. The problem is my back button is disabled. So when I close the document, I don't have my webpage in another window.
How can I either activate the back button or open the PDF file in a new window?
Open PDF new window
Jan 15, 2007 01:43 AM|Haissam|LINK
Create a blank webform (i have named it here WebForm2) which will open and the pdf file will open in it.
string filePath = ur file path on the server;
Session["pdfFileName"] = filePath ;
put the above code in a page and in the page_load of the WebForm2
if (Request.QueryString("pdf") == 'yes')
Jan 15, 2007 11:26 PM|Blazingfun|LINK
Thanks for the response.[:)]
I should have mentioned that I am using VB and .NET ver 2.0.
When I use Page.RegisterStartupScript I get a message telling me that page.registerStartupScript is obsolete. So I tried
This does not change my current page or open a new window. It is like I am missing another command to activate the new script in a new window.
I also tried viewState, but it is limited to the current page and is not available on the next page so I passed the parm in the URL.
I did create a new page and used Response.Redirect("displayPDF.aspx?FileName=" & fullUploadPath) to open my new page,
Then in my new page I coded
fullUploadPath = Request.Params(
This doesn't open a new page, it uses my current page to show the PDF file and then I can use the back button to return to my selection page.
Thanks for your help!
Jan 16, 2007 02:10 AM|Haissam|LINK
"Test", "window.open('displayPDF.aspx?FileName=' & fullUploadPath)")
i think it was a syntax error from your side :)
Jan 16, 2007 09:47 PM|Blazingfun|LINK
I tried both solutions, as written and they give me different results. I moved the single quote around and got one of them to work.
The clientScript. solution does not load my PDF, but it does reload my current page and when I view source the window.open command is at the bottom of the HTML source
window.open('displayPDF.aspx?FileName='January 2007 short.pdf)</form>
or if I move the single quote I get the following as the last lines in my source.
I did get it to open a new page and display the PDF file, with response.write after moving the ' single quote to after the fullUploadPath ( I have added extra spaces to highlight the single quote.)
BUT. My original page now loses its formating. (the controls were centered and now they are left aligned).
" ' )</script>")
Jan 17, 2007 02:15 AM|Haissam|LINK
first try to remove the Response.Write() and use ClientScript.RegisterStartupScript(GetType(String),
"Test", "window.open('displayPDF.aspx?FileName=' & fullUploadPath)")
because the first one messes up the HTML code.
concerning the formatting on your original page, try to check that you are not changing it's alignment as the code provided above worked good for me.
May 01, 2007 01:23 AM|Robert Barnes|LINK
This sounds like a problem that I had,
The suggestion that worked was to use an Iframe, and set it's src attribute to the document link. (read for more about
iframes). This was dead easy as long as I had a constant for the name of the document, but there was a bit of bother setting the src attribute
from the program until Haissam showed me how to do this.
I was using this for a .htm document, but it would work equally well for .doc, .pdf, or anything that the client computer can handle.
May 04, 2007 06:27 AM|Jeethu|LINK
The most simple solution for this is create a simple iframe ans set the source pdf , it will load inside the webform [:)]
IIS/Asp.Net Engineer Microsoft.
Sep 15, 2008 06:10 AM|ave_prasad|LINK
Hi I am Arun Prasad.B from India. I want to display pdf in asp.net with disabling the printing and save options in pdf viewer. As well as I want to restrict the context menu in Pdf Viewer. If any one knows please guide me.
Sep 15, 2008 06:29 AM|thusharapp|LINK
I want to display pdf in asp.net with disabling the printing and save options in pdf viewer.Plz help
Oct 17, 2008 03:04 AM|truongthang|LINK
Can you try to use this open source control.
Dec 06, 2008 06:39 AM|yogarajan143|LINK
do u have any solution in asp.net with pdf and print and save as property disable
i need very urgent
pls help me
Jul 02, 2009 05:08 AM|LucBite|LINK
I want to use your solution(
) to display different documents on the iframe based on what the user wants to see. for example affter a user has selected some option from a drop downlist the iframe shoul display the pdf document related to their option. please help.
Jul 02, 2009 05:23 AM|srinivaskotra|LINK
to open pdf file
asp.net with pdf and print and save as property disable this is your post
Not posible since that's the browser property. what you can only do is add a watermark to the PDF so that it becomes unusable
Apr 07, 2010 04:43 AM|s_luckman1|LINK
This way it works
Dim filePath As
Response.ContentType = "application/pdf"
place the above code in pageload in webform2.aspx
Working as expected, I mean the back button is working.
Jul 15, 2010 11:00 AM|bioscom|LINK
Thanks for this post. I have an application which I developed in 2007 in ASP.NET 2.0 framework.
There is a need for the application to display PDF file for user preview, which I did using iframe as you adviced.
But when file to be displayed is downloaded by the application, users will have to click the refresh button on the web browser before the current PDF file is displayed, sometimes it doesn't work.
Please, what can I do to ensure that once the page is loaded, the correct file displays.
The correct file is actually downloaded, because when I go in to the folder where the downloaded file is, it is the one requested that I see there.
Oct 12, 2010 12:10 AM|rajeshprasath|LINK
There are various approaches used to display PDF documents in a webpage. Displaying PDF documents in a webpage using simple ASP.NET custom server control or Directly rendering the PDF documents on the webpage. So if you want to know more details on these
approaches, you can refer following links.
Dec 17, 2010 04:55 PM|Robert Barnes|LINK
More: I found different behaviour with various browsers: -
Here is my code: -
1. In the page definition (.aspx) I wrote: -
<iframe id="ifrStory" runat="Server" ... />
2. In my code-behind I wrote: -
ifrStory.Attributes.Add("src", "http://" & Request.Url.Authority & Request.ApplicationPath & Mid(document.DOCPath, 2))
"http://" & Request.Url.Authority &
was added to make this work with Chrome, but is unnecessary with Firefox and IE.
This worked correctly with IE and Chrome, opening in the iframe. However with Firefox it may open in a separate tab. This appears to be related to whether Firefox uses a plugin for the object type.
I hope this is useful,
Sep 03, 2011 02:35 AM|s4lin4u|LINK
Please try this
string path = @"C:\Swift3D.pdf";
WebClient client = new WebClient();
Byte buffer = client.DownloadData(path);
if (buffer != null)
Response.ContentType = "application/pdf";
Sep 03, 2011 02:51 AM|manishGeetu|LINK
Hi, I need to display a pdf document inside a web form. I know how to do so using an hyperlink control (NavigateUrl property), but in this case I need to display the pdf as a result of an internal process,
not the click of a link by the user. There is any way to do so? Thanks in advance.
Sep 03, 2011 02:53 AM|s4lin4u|LINK
use Response.Redirect("pdfpath/pdfdoc.pdf"); in page load
Sep 03, 2011 02:27 PM|siteslayer|LINK
There is a very nice Open source control called Show pdf that I implemented just now on my app.