Wednesday, September 12, 2007

asp.net - Display inline PDF on webpage

Embed PDFs into a Web Page with a Custom Control - The Code ... This article describes an approach to embedding and displaying PDF documents in a web page through the use of a simple ASP.NET 2.0 custom server control. The approach indicated herein allows the developer the opportunity to control the web page content surrounding the embedded PDF; this is in contrast to linking directly to a PDF which uses the entire web page to display PDF but does not otherwise permit the developer to control the appearance of the page.

-----------------------
Honestly I think that this approach is an error prone and overbloan method of creating an IFrame. A much simpler method of accomplishing what I needed in this instance is:
System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath(cPage.RedirectURL));

Response.Clear();
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/pdf";
Response.WriteFile(file.FullName);
Response.End();

No comments: