Print Form in ASP.NET

Posted by Emil under ASP.NET on 10/3/2011 | Points: 10 | Views : 1950 | Status : [Member] | Replies : 2
How to print a particular part in web form?
i have used javascript print function. When i take print print is coming very small.
How to adjust the size of print?


Posted by: DotNetguy on: 10/4/2011 [Member] Starter | Points: 25

Hi Try this

<head >

<script type="text/javascript">

function printDIV()
var headstr = "<html><head><title></title></head><body>";
var footstr = "</body></html>";
var newstr = document.getElementById('divID').innerHTML;
var oldstr = document.body.innerHTML;
document.body.innerHTML = headstr + newstr + footstr;
document.body.innerHTML = oldstr;
return false;

<body >
<form id="form1" runat="server">
<input name="b_print" type="button" onclick="printDIV();" value=" Print " />
<div id="divID">
<h1 style="color:green">
The Div content which you want to print</h1>


Emil, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Reena_jainy2k1 on: 10/4/2011 [Member] Starter | Points: 25

se this code, all thing explained in the code

PrintDocument PrintDoc1 = new PrintDocument();
PrintPreviewDialog PrintPreviewDialog1 = new PrintPreviewDialog();

private void btn_PrintPreview_Click(object sender, EventArgs e)
{// When PrintPreview Button Clicks
PrintPreviewDialog1.Document = PrintDoc1;
PrintDoc1.OriginAtMargins =true; //To set or Get the Position of a Graphic Object
PrintDoc1.PrintPage += PDoc_PrintPage;

private void PDoc_PrintPage(object sender, PrintPageEventArgs e)
Bitmap bmp = new Bitmap(this.Width, this.Height);
//this.DrawToBitmap(bmp, this.ClientRectangle);
this.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height)); //Takes the Snap of the Exact WindowForm size as Bitmap image
e.Graphics.DrawImage(bmp, 0, 0);

private void btn_PrintPage_Click(object sender, EventArgs e)
{//When Print Button Clicks, Image will be show & Ready to Print

Reena Jain
Project Manager

Emil, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response