How print a page in A3 format with Paper Size as A3 RRS feed

  • Question

  • Hi,

    I would like to print my Winform page in A3 format with all the details when user clicks on a button "Print" . Can someone please suggest me some sample source code to work this perfectly. I have tried many posts so far but none of them are working.

    I have found some sample source code related to Asp.net but this also not working properly. It's printing the page but only in A4 format..

    Please help me .This is an urgent requirement


    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.IO;
    using System.Text;
    using System.Web.SessionState;
    using System.Drawing.Printing;

    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();
            frm.Attributes.Add("runat", "server");
            string strHTML = stringWrite.ToString();

            PaperSize p = null;
            PrintDocument pd = new PrintDocument();

            pd.PrinterSettings.DefaultPageSettings.Landscape = true;

            pd.PrinterSettings.DefaultPageSettings.PaperSize.Height = 420;

            pd.PrinterSettings.DefaultPageSettings.PaperSize.Width = 297;

            //foreach (PaperSize ps in pd.PrinterSettings.PaperSizes)
            //    if (ps.PaperName.Equals("A3"))
            //        p = ps;

            //pd.DefaultPageSettings.PaperSize = p;

            pd.DefaultPageSettings.PaperSize = p;

            HttpContext.Current.Response.Write(@"<link href='/Style1.css' rel='stylesheet' type='text/css' />");


    and in print button click event


    //Call the method

    protected void Button1_Click(object sender, EventArgs e)


    • Moved by Mike Feng Wednesday, April 17, 2013 12:52 PM
    Tuesday, April 16, 2013 5:42 AM


  • This forum is about the Graphical User Interface Windows Forms. 

    A likewise category is for the Microsoft ASP.Net user interface



    • Proposed as answer by Mike Feng Wednesday, April 17, 2013 12:52 PM
    • Marked as answer by Just Karl Friday, October 11, 2013 2:37 PM
    Tuesday, April 16, 2013 10:55 AM

All replies