I am trying to implement a demo certificate issue for my course project. While converting the aspx page to pdf, the image is not getting displayed at all. The image used here is in my own laptop in the same folder as that of the Certification.aspx file. In another laptop, the image is shown once but again the image is not shown. It is happening in random basis.
Please help.
Thanks.
This is the Certificatication.aspx page
This page shows a course portal logo as an image and a line of text about the certificate.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Certification.aspx.cs" Inherits="Certification" EnableEventValidation="false" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<!-- <asp:Image ID="Image1" runat="server" Height="402px" ImageUrl="certi.png" Width="923px" /> -->
<br />
<br />
<br />
<asp:Panel ID="Panel1" runat="server" Height="120px">
<!-- <img src = "http://www.aspsnippets.com/images/Blue/Logo.png" /><br /> -->
<img src="E:\Pictures\1.jpg" height="402" width="923" alt="Image" /><br/>
<asp:Label ID="Label3" runat="server"></asp:Label>
<br />
<br />
<b><i>Has successfully completed the requirements to complete the course on</i></b>
<asp:Label ID="Label4" runat="server"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" Text="Click to download as PDF." OnClick="Button1_Click1" />
</asp:Panel>
</div>
</form>
This is the Certification.aspx.cs file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using System.Drawing;
using System.IO;
public partial class Certification : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string marks="",name="",course="";
int marks1=0;
string id = Session["email"].ToString();
SqlConnection conn = new SqlConnection(); //creating connection reference object
//conn.ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\My Documents\Final Year Project\finalyear\finalyear\App_Data\newdatabase.mdf;Integrated Security=True";
conn.ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\My Documents\Final Year Project\finalyear\finalyear\App_Data\newdatabase.mdf;Integrated Security=True";
conn.Open(); //opening connection
string q = "select * from selectcourse where selectcourse.s_emailid='" + id + "'";
SqlCommand cmd = new SqlCommand(q, conn);
//execute query
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read() == true)
{
marks = reader.GetValue(3).ToString();
marks1 = Convert.ToInt32(marks);
}
reader.Dispose();
cmd.Dispose();
string q1 = "select * from studentinfo where studentinfo.s_emailid='" + id + "'";
SqlCommand cmd1 = new SqlCommand(q1, conn);
//execute query
SqlDataReader reader1 = cmd1.ExecuteReader();
if (reader1.Read() == true)
{
name = reader1.GetValue(1).ToString();
}
course = Session["course"].ToString();
Label3.Text = name.ToString();
Label4.Text = course.ToString();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
string attachment = "attachment; filename=" + "abc" + ".pdf";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/pdf";
StringWriter s_tw = new StringWriter();
HtmlTextWriter h_textw = new HtmlTextWriter(s_tw);
h_textw.AddStyleAttribute("font-size", "7pt");
h_textw.AddStyleAttribute("color", "Black");
Panel1.RenderControl(h_textw);//Name of the Panel
Document doc = new Document();
doc = new Document(PageSize.A4, 5, 5, 15, 5);
FontFactory.GetFont("Verdana", 80);
PdfWriter.GetInstance(doc, Response.OutputStream);
doc.Open();
StringReader s_tr = new StringReader(s_tw.ToString());
HTMLWorker html_worker = new HTMLWorker(doc);
html_worker.Parse(s_tr);
/*var logo = iTextSharp.text.Image.GetInstance(Server.MapPath("certi.png"));
logo.SetAbsolutePosition(0, 0);
doc.Add(logo);*/
doc.Close();
Response.Write(doc);
}
}
The aspx page gets converts to pdf on the click of the above button.