0

ASP.NET で webcontol を印刷するときに、「Page 1 of 1」やフッター (url) などのヘッダーを非表示にするにはどうすればよいですか?

私は現在、[印刷]ボタンをクリックして新しいページを開き、そのページでandeを実行しています

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

これにより、ヘッダーとフッターが印刷されます。それを避ける方法は?

4

4 に答える 4

1

CSS スタイルを使用し、それらが印刷のメディア タイプに適用されることを指定する必要があります。ヘルプについては、この記事を参照してください。http://www.cantoni.org/articles/printstyle

基本的には、印刷スタイル専用のスタイルシートを別途作成してください。ページ上の何かを隠したい場合は{ display:none }、その要素のスタイル属性の 1 つとして使用します。次に、スタイルシートを HEAD 要素にリンクします。

<link href="print.css" media="print" type="text/css" rel="stylesheet" />
于 2009-06-17T13:11:21.803 に答える
1

この設定は、ユーザーがブラウザで構成します。コードから無効にする方法はありません。設定を構成/無効にする方法に関する指示を含めることをお勧めします。

ここで例を参照してください: http://www.xheo.com/products/sps/default.aspx?print=true

于 2009-06-17T08:14:53.227 に答える
0

このために、私たちはそれのような印刷クラスを使用しています

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

ここでは、フォームプロパティの行を変更して設定するだけです

frm.ResolveUrl("");

したがって、ページが印刷されているときはURlは表示されません。

于 2011-07-30T12:46:19.000 に答える
0

Firefox を使用している場合、クライアントにこのアドオンをインストールさせることができます。

それ以外の場合、Internet Explorer を使用している場合: 「MeadCo ScriptX」を google で検索します。

(FFオプションは無料、IEオプションは基本機能のみ無料)

于 2009-12-01T20:07:31.743 に答える