Please refer these links from where i have created this sample.
http://www.mikesdotnetting.com/Article/86/iTextSharp-Introducing-Tables
Display preview of image locally without uploading to Server
Print specific part of web page in ASP.Net
I have used the ItextSharp DLL you can download it from this article.
Create PDF Report from database in ASP.Net using C# and VB.Net
On click of button the page data will be exported to Pdf and the same page will be printed.
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
table
{
border: 1px solid #ccc;
}
table th
{
background-color: #F7F7F7;
color: #333;
font-weight: bold;
}
table th, table td
{
padding: 5px;
border-color: #ccc;
}
border
{
outline: none;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(function () {
$("#fuProfileImage").change(function () {
$("#dvPreview").html("");
var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.jpg|.jpeg|.gif|.png|.bmp)$/;
if (regex.test($(this).val().toLowerCase())) {
if ($.browser.msie && parseFloat(jQuery.browser.version) <= 9.0) {
$("#dvPreview").show();
$("#dvPreview")[0].filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = $(this).val();
}
else {
if (typeof (FileReader) != "undefined") {
$("#dvPreview").show();
$("#dvPreview").append("<img height='200' width='250'/>");
var reader = new FileReader();
reader.onload = function (e) {
$("#dvPreview img").attr("src", e.target.result);
}
reader.readAsDataURL($(this)[0].files[0]);
} else {
alert("This browser does not support FileReader.");
}
}
} else {
alert("Please upload a valid image file.");
}
});
});
</script>
<script type="text/javascript">
function OpenPrint() {
window.open('Default2.aspx');
}
function PrintPanel() {
var panel = document.getElementById("<%=pnlContents.ClientID %>");
var printWindow = window.open('', '', 'height=400,width=800');
printWindow.document.write('<html><head>');
printWindow.document.write('</head><body >');
printWindow.document.write(panel.innerHTML);
printWindow.document.write('</body></html>');
printWindow.document.close();
setTimeout(function () {
printWindow.print();
}, 500);
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID="pnlContents" runat="server">
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td>
Name
</td>
<td>
<asp:TextBox ID="txtName" Text="John Hammond" runat="server" CssClass="border" />
</td>
</tr>
<tr>
<td>
City
</td>
<td>
<asp:TextBox ID="txtCity" Text="Washington" runat="server" CssClass="border" />
</td>
</tr>
<tr>
<td>
Country
</td>
<td>
<asp:TextBox ID="txtCountry" Text="United States" runat="server" CssClass="border" />
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
Profile Image
</td>
<td>
<div id="dvPreview">
</div>
</td>
</tr>
</table>
<br />
</asp:Panel>
<asp:FileUpload ID="fuProfileImage" runat="server" />
<asp:Button runat="server" Text="Print and Export" OnClick="PrintExport" OnClientClick="PrintPanel();" />
</div>
</form>
</body>
</html>
Namespace
using System.IO;
using System.Drawing.Imaging;
using iTextSharp.text;
using iTextSharp.text.pdf;
C#
protected void PrintExport(object sender, EventArgs e)
{
if (this.fuProfileImage.HasFile)
{
//Save the image in Image folder under the root directory
this.fuProfileImage.PostedFile.SaveAs(Server.MapPath("~/Images/") + this.fuProfileImage.FileName);
//Export to PDF
Document doc = new Document(iTextSharp.text.PageSize.A4);
System.IO.MemoryStream str = new System.IO.MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(doc, str);
doc.Open();
//Adding user Image in PDF
iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Images/") + this.fuProfileImage.FileName);
logo.ScalePercent(12f);
logo.Alignment = 1; //1 for center
doc.Add(logo);
PdfPTable table = new PdfPTable(2);
table.AddCell("Name:");
table.AddCell(this.txtName.Text.Trim());
table.AddCell("City");
table.AddCell(this.txtCity.Text.Trim());
table.AddCell("Country");
table.AddCell(this.txtCountry.Text.Trim());
table.SpacingBefore = 6.0f;
doc.Add(table);
doc.Close();
Response.AddHeader("Content-Disposition", "attachment;filename=report.pdf");
Response.ContentType = "application/pdf";
Response.BinaryWrite(str.ToArray());
str.Close();
Response.End();
}
}
Screenshot
Default.aspx

Printed Page

PDF
