Hi Tevin,
Refer below sample.
HTML
<asp:Panel ID="PanelEmployeeMedicalHistory" CssClass="panel panel-default absolutePrintElement"
Enabled="true" runat="server">
<div class="panel-heading" style="text-align: center;">
Employee Medical History</div>
<div class="panel-body">
<div class="form-row">
<div class="col">
</div>
<div class="col">
<img runat="server" id="ImgLogo" src="http://www.lumotech.co.za/images/img_who-we-are_logo.png"
style="width: 200px;" />
</div>
<div class="col">
</div>
</div>
<br />
<div class="form-row">
<div class="col-3">
</div>
<div class="col">
<asp:Label ID="lblAddress" runat="server" Font-Bold="true" ForeColor="#0099ff" Text="Fitzpatrick St, Cape Road Industrial | Uitenhage | P.O.Box 277 | 6229 | 041 9953016"> </asp:Label>
</div>
<div class="col-3">
</div>
</div>
<hr />
<asp:Repeater ID="RepeaterEmployee" runat="server">
<ItemTemplate>
<table id="Table1" runat="server" class="table table-default table-striped table-bordered table-condensed">
<tr>
<td colspan="2" style="text-align: center;">
<asp:Image ID="Image1" runat="server" ImageAlign="Middle" ImageUrl='<%# GetUrl(Eval("Photo").ToString()) %>' />
</td>
</tr>
<tr>
<td style="vertical-align: middle;">
</td>
<td>
<table id="Table2" runat="server" style="width: 100%;">
<tr>
<td>
<b>First Name:</b>
</td>
<td>
<asp:Label ID="FirstName" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
<b>Employee Code:</b>
</td>
<td>
<asp:Label ID="lblCode" runat="server" Text='<%#Eval("Code") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
<b>Medical Report:</b>
</td>
<td>
<asp:LinkButton ID="btnDownload" Text="Download Medical Report" OnClick="btnDownload_Click"
CommandName="Download" CommandArgument='<%#Eval("Code") %>' runat="server"></asp:LinkButton>
</td>
</tr>
</table>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</div>
</asp:Panel>
Namespaces
C#
using System.Data;
using System.IO;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text;
using iTextSharp.text.pdf;
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
BindRepeater();
}
}
private void BindRepeater()
{
DataTable dt = GetData();
RepeaterEmployee.DataSource = dt;
RepeaterEmployee.DataBind();
}
private static DataTable GetData()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("Photo", typeof(string)), new DataColumn("Name", typeof(string)), new DataColumn("Code", typeof(int)) });
dt.Rows.Add("ASPSnippetsLogo.png", "Mudassar", 1);
dt.Rows.Add("ASPSnippetsLogo.png", "John", 2);
return dt;
}
protected void btnDownload_Click(object sender, EventArgs e)
{
DataTable dt = GetData();
LinkButton button = (sender as LinkButton);
string commandArgument = button.CommandArgument;
RepeaterItem item = button.NamingContainer as RepeaterItem;
int index = item.ItemIndex;
int lblCode = Convert.ToInt16((item.FindControl("lblCode") as Label).Text);
RepeaterEmployee.DataSource = dt.Select("Code=" + lblCode + "").CopyToDataTable();
RepeaterEmployee.DataBind();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
PanelEmployeeMedicalHistory.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document();
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
Response.Write(pdfDoc);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.End();
}
protected string GetUrl(string imagepath)
{
string[] splits = Request.Url.AbsoluteUri.Split('/');
if (splits.Length >= 2)
{
string url = splits[0] + "//";
for (int i = 2; i < splits.Length - 1; i++)
{
url += splits[i];
url += "/";
}
return url + imagepath;
}
return imagepath;
}
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
Screenshot