Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi masters
i want to display a pdf in a panel with asp.net
i use this code and display that in whole of page :

WebClient User = new WebClient();
Byte[] FileBuffer = File.ReadAllBytes(filepath);//User.DownloadData(filepath);
if (FileBuffer != null)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", FileBuffer.Length.ToString());
Response.BinaryWrite(FileBuffer);

}
C#

Posted

Once you try this take iframe and give your pdf path to src of iframe . in iframe block it will be displayed
like this: in aspx page

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm5.aspx.cs" Inherits="WebApplication1.WebForm5" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>    
        <asp:Panel runat="server" ID=panepdf">
          <iframe src="EMeditime_Broucher_Pages.pdf">        
        </iframe>   
        </asp:Panel> 
  <asp:Button Text="pdf File" runat="server" ID="btnPdf" OnClick="btnPdf_Click" />
       
    </div>
    </form>
</body>
</html>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;

namespace WebApplication1
{
    public partial class WebForm5 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                panepdf.Visible = false;
            }
        }
        protected void btnPdf_Click(object sender, EventArgs e)
        {
            panepdf.Visible = true;
        }
    }
}
 
Share this answer
 
v3
Comments
mbmkris 8-Aug-16 8:53am    
Hi Samantha Reddy,

If i need to run solution in run time, code behind how to manage to display a PDF in panel or some part in the page.
do you want to open a .pdf file content inside a panel?
Try this,

XML
<asp:Panel ID="Panel1" runat="server">
    <iframe src="UploadFiles/RR Form_MP, BCA(P)_MCA_1501.pdf" width="400px" height="300px"  />
    </asp:Panel>
 
Share this answer
 
Comments
Ehsanf3 9-Oct-14 2:08am    
this work automatically on page load
but i want to display after click a button
i am a beginner in asp.net
Samatha Reddy G 9-Oct-14 2:15am    
in page load you need to put visible false to that panel and after clicking on button change that to visible true
Ehsanf3 9-Oct-14 2:24am    
when i put my source in iframe src , after click button Does not show anything.

<asp:Panel ID="Panel1" runat="server" Visible ="false">
<iframe src ="\\App_Data\\1.pdf" width="500px" height="1000"> </iframe>
Samatha Reddy G 9-Oct-14 2:33am    
i will give the code just copy and execute it



Samatha Reddy G 9-Oct-14 2:39am    
i gave the solution try it then also if you wont get the result , then please explain your problem.
Hi,

There are some free Scripts which will help you to do the same.

1.http://www.pdfobject.com/[^]
2. https://mozillalabs.com/en-US/pdfjs/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900