从ASP.NET站点打印到网络打印机

时间:2013-09-13 21:50:07

标签: c# asp.net printing

我在打印到网络打印机时遇到问题。下面的代码在我自己的笔记本电脑和Visual Studio上工作正常,但是当该站点在IIS 8网站(在Windows Server 2008 R2上)上运行时,单击打印机按钮什么都不做..页面刚刚开始加载(永远加载和超时),但没有任何反应,也没有任何作业被添加到打印机的队列中..

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            int i = 0;
            foreach (string s in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
            {
                Button b = new Button();
                b.ID = "Print_" + i;
                b.Text = s.ToString();
                b.Click += b_Click;
                test.Controls.Add(b);
                i++;
            }

        }

        void b_Click(object sender, EventArgs e)
        {
            string printer = ((Button)sender).Text;
            PrintDocument p = new PrintDocument();
            p.PrinterSettings.PrinterName = printer;
            p.PrintPage += p_PrintPage;

            p.Print();
        }


        void p_PrintPage(object sender, PrintPageEventArgs e)
        {
            e.Graphics.DrawString("testpage", new System.Drawing.Font("Arial", 12), Brushes.Black, new PointF(200, 200));
        }
    }

0 个答案:

没有答案