Print Form in ASP.NET

Posted by Emil under ASP.NET on 10/3/2011 | Points: 10 | Views : 2013 | 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?




Responses

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

Up
0
Down
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;
window.print();
document.body.innerHTML = oldstr;
return false;
}
</script>

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

</div>
</form>
</body>
</html>

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

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

Up
0
Down
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;
PrintPreviewDialog1.ShowDialog();
}

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
PrintDoc1.Print();
}

Reena Jain
Project Manager

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

Login to post response