asp.net을 사용하여 웹 콘트롤을 인쇄하는 동안 헤더와 바닥 글을 숨기십시오.

StackOverflow https://stackoverflow.com/questions/1005652

문제

ASP.NET에서 WebContol을 인쇄 할 때 '1/1 페이지 1'및 Footer (URL)와 같은 헤더를 어떻게 숨길 수 있습니까?

나는 현재 인쇄 버튼에 새 페이지를 열어서하고 있습니다.

protected void Page_Load(object sender, EventArgs e)
{
    if( null != Session["Control"] )
    {
        Control ctrl = ( Control )Session["Control"];
        PrintManager.PrintWebControl( ctrl );
        Session["Control"] = null;
    }
}

이것은 헤더와 바닥 글을 인쇄합니다. 그것을 피하는 방법?

도움이 되었습니까?

해결책

That setting is configured by the user in their browser. Their is no way to disable it from code. You'r best bet is to include instructions on how to configure/disable the settings.

See an example here: http://www.xheo.com/products/sps/default.aspx?print=true

다른 팁

You should use CSS styles and specify they apply to a media type of print. See this article for help; http://www.cantoni.org/articles/printstyle

Basically create a seperate stylesheet for print styles only. If you want to hide something on the page use { display:none } as one of that elements style attributes. Then link your stylesheet in the HEAD element;

<link href="print.css" media="print" type="text/css" rel="stylesheet" />

For this we are using print class like it

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);
    // done changes on below 1 line for unassigned header URL //
    frm.ResolveUrl("");
    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();
}

here just change a line in form property and set

frm.ResolveUrl("");

so URl is not visible when page is print..i use it successfuly.

If you're using Firefox, and you can have the client install this add-on.

Otherwise, if you are using Internet Explorer: google for "MeadCo ScriptX"

(FF option is free, IE option is free for basic functionality only)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top