PDF files are a standard method in disseminating information on a website. PDF files lock the document from being edited to allow website owners the ability to provide documentation without any changes. An iframe is a way for website owners to display a PDF file within a webpage without the browser opening a full PDF window. This can be accomplished using .NET and C#.
- Skill level:
Other People Are Reading
Upload the PDF file to a directory on the web host. You need to take note of the location of the PDF file, because it's used in the settings for the iframe.
Add the iframe to your ASP.NET web page. An iframe is similar to a "page within a page," so you need to place the iframe in a position where readers can easily see the PDF file. Below is the code for an iframe: <iframe runat="server" id="myPDF" src="www.your_domain.com/temporaryfile.htm"></iframe> The "temporaryfile.htm" is used as a placeholder for the iframe. It's replaced during start-up of the web page.
Add the C# code to the page_load function in the code behind file of the .NET web page. To access the page_load function, right-click the file in your Visual Studio .NET workspace and select "View Code" from the menu. This will bring you to the function that runs every time the web page is loaded. Within this function, add the following code: myPDF.Attributes.Add("src", "<location_of_pdf>"); The "<location_of_pdf>" should be replaced with the URL of the PDF file uploaded at step 1.
Test the web page by opening a web browser and navigating to the web page. The PDF should load into the iframe when the web page loads.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for