PDA

View Full Version : پرینت در asp



sajad_boj70
دوشنبه 29 دی 1393, 10:37 صبح
سلام. دوستان من میخوام یک صفحه رو به کمک جاوا اسکریپت پرینت بگیرم ولی css هایی که استفاده کردم هنگام پرینت اعمال نمیشه ! میتونید راهنمایی کنید دلیلش چیه؟

aminmousavi
دوشنبه 29 دی 1393, 11:07 صبح
سلام دوست عزیز ، اگر منظورتون backgroud و ... هست . بخطار مرورگر این اتفاق می افته .
برای رفع این مساله : (chrome)
- CTRL+P
-MORE Setting
- مقدار Backgroud Graphics رو true کنین

sajad_boj70
دوشنبه 29 دی 1393, 11:43 صبح
نه عزیر مشکل این نیست.
ببینید من برای پرینت گرفتن یک کلاس تعریف کردم به این صورت :


public class PrintHelper
{
public PrintHelper()
{

}
public static void PrintWebControl(Control ctrl)
{
PrintWebControl(ctrl, string.Empty);
}

public static void PrintWebControl(Control ctrl, string Script)
{
StringWriter stringWrite = new StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
if (ctrl is WebControl)
{
Unit w = new Unit(100, UnitType.Percentage); ((WebControl)ctrl).Width = w;


}
Page pg = new Page();
pg.EnableEventValidation = false;
if (Script != string.Empty)
{
pg.ClientScript.RegisterStartupScript(pg.GetType() , "PrintJavaScript", Script);
}
HtmlForm frm = new HtmlForm();
pg.Controls.Add(frm);
frm.Attributes.Add("runat", "server");
frm.Controls.Add(ctrl);

pg.DesignerInitialize();
pg.RenderControl(htmlWrite);

string strHTML = stringWrite.ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.Write("<script>window.print();</script>");
HttpContext.Current.Response.End();

}


بعد اومدم تو صفحه مورد نظرم و مواردی رو که میخوام پرینت بگیرم رو تو یک panel گذاشتم و در دکمه پرینتم این کد ها رو نوشتم :


Session["ctrl"] = Panel1;
ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('Print.aspx','href=css/pr.css','PrintMe','height=441px,width=700px,scroll bars=1,');</script>");
Control ctrl = (Control)Session["ctrl"];
PrintHelper.PrintWebControl(ctrl);