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.
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.
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
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
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).
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.
azayas48
Member
20 Points
4 Posts
How to display a pdf document inside a web form?
Aug 26, 2006 12:49 AM|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.
pdf document display web forms
Javier Luna
Contributor
2436 Points
592 Posts
Re: How to display a pdf document inside a web form?
Aug 31, 2006 08:11 PM|LINK
Hi azayas48,
That will be very slow. I don't recommend it. You would to use open PDF file in new window.
Good Coding!
Javier Luna
http://guydotnetxmlwebservices.blogspot.com/
priyap
Member
10 Points
2 Posts
Re: How to display a pdf document inside a web form?
Oct 02, 2006 05:01 PM|LINK
Hello,
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.
<OBJECT>Classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" VIEWASTEXT
<PARAM NAME="SRC" VALUE="<%= Me.strPAth %>"
</OBJECT>
Where Me.strPAth is a module level string int he code behind page.
Good luck!!
Priya.
Haissam
All-Star
37421 Points
5632 Posts
Re: How to display a pdf document inside a web form?
Oct 06, 2006 10:48 PM|LINK
in order to display a pdf file inside a webform u have to do the following after certain processing
Response.Clear();
string filePath = ur file path on the server
Response.contentType = "application/pdf";
Response.WriteFile(filePath);
Happy Coding
MCAD.NET
| Blog |
Blazingfun
Member
6 Points
4 Posts
Re: How to display a pdf document inside a web form?
Jan 14, 2007 09:52 PM|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
Haissam
All-Star
37421 Points
5632 Posts
Re: How to display a pdf document inside a web form?
Jan 15, 2007 05:43 AM|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 ;
Page.RegisterStartUpScript("Myscript","window.open('WebForm2.aspx?pdf=yes')");
put the above code in a page and in the page_load of the WebForm2
if (Request.QueryString("pdf") == 'yes')
{
Response.contentType = "application/pdf";
Response.WriteFile(Session["pdfFileName"]);
}
Happy Coding
MCAD.NET
| Blog |
Blazingfun
Member
6 Points
4 Posts
Re: How to display a pdf document inside a web form?
Jan 16, 2007 03:26 AM|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
ClientScript.RegisterStartupScript(
GetType(String), "Test", "window.open('displayPDF.aspx?FileName=" & fullUploadPath & "')")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(
"FileName")Response.ContentType = "application/pdf"
Response.AddHeader("Content-Type", "application/pdf")
Response.WriteFile(fullUploadPath)
Response.End()
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!
Haissam
All-Star
37421 Points
5632 Posts
Re: How to display a pdf document inside a web form?
Jan 16, 2007 06:10 AM|LINK
Dear,
can u try Response.Write("<script language=javascript>window.open('displayPDF.aspx?FileName=' & fullUploadPath;</script>")
or ClientScript.RegisterStartupScript(GetType(String), "Test", "window.open('displayPDF.aspx?FileName=' & fullUploadPath)")
i think it was a syntax error from your side :)
Happy Coding
MCAD.NET
| Blog |
Blazingfun
Member
6 Points
4 Posts
Re: How to display a pdf document inside a web form?
Jan 17, 2007 01:47 AM|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
</div>
window.open('displayPDF.aspx?FileName='January 2007 short.pdf)</form>
</body>
</html>
or if I move the single quote I get the following as the last lines in my source.
</div>
window.open('displayPDF.aspx?FileName=December 2006.pdf')</form>
</body>
</html>
---------------------------------------------------------------------------------------------------------------------------------------------
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).
Response.Write("<script language=javascript>window.open('displayPDF.aspx?FileName=" & fullUploadPath & " ' )</script>")
Thanks.
Haissam
All-Star
37421 Points
5632 Posts
Re: How to display a pdf document inside a web form?
Jan 17, 2007 06:15 AM|LINK
Dear,
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.
Happy Coding
MCAD.NET
| Blog |