我可以使用PrintDocument打印到客户端服务器上的打印机吗?

时间:2014-06-26 15:28:24

标签: c# asp.net printing

我在ASP.NET C#(Windows窗体)中有以下代码,我可以将其打印到本地PC上的打印机。但我想要做的是能够打印到服务器上的打印机。无论如何都要指定服务器地址和打印机名称?

我为了测试目的而对打印机名称进行了硬编码。此printerName是服务器上的打印机。如果我用本地PC上的打印机替换它,则打印出来。我只是不知道如何在服务器上指定打印机的正确路径。

    private void btnEnter_Click(object sender, EventArgs e)
    {

        printerName = "AMI-Zebra";                      // on ABB system

        printerServer = "172.18.10.22";
        trans = "132980877";
        qty = txtQty.Text;


        Printing(PrinterName);

    }


    private void Printing(string pname)
{
    PrintDocument printDoc = new PrintDocument();
        printDoc.PrinterSettings.PrinterName = pname;

        PageSettings ps = new PageSettings();
        PaperSize pz = new PaperSize();

        pz.Height = 650;
        pz.Width = 400;
        ps.PaperSize = pz;

        printDoc.DefaultPageSettings = ps;
        printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);  
    printDoc.Print();
}

    private void printDoc_PrintPage(Object sender, PrintPageEventArgs e)
    {           
        string cnstr = ConnString; 

        string wc = string.Empty;
        string item = string.Empty;

        string currDt = DateTime.Today.ToShortDateString();     // sam new 11/20/2012


        //Pen p1   = Pens.Black;
        Pen p2 = new Pen(Color.Black, 2);
        Pen p3 = new Pen(Color.Black, 3);

        Brush b1 = System.Drawing.Brushes.Black;

        Font f1 = new System.Drawing.Font("Arial", 14, FontStyle.Bold);
        Font f2 = new System.Drawing.Font("Arial", 12);
        Font f3 = new System.Drawing.Font("Arial", 20, FontStyle.Bold);
        Font f4 = new System.Drawing.Font("Arial", 16, FontStyle.Bold);
        Font f5 = new System.Drawing.Font("Arial", 30, FontStyle.Bold);   

        Font fb = new Font("Free 3 of 9", 40);


        System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(StringFormatFlags.DirectionVertical);

        e.Graphics.DrawString("WIP LABEL", f5, b1, 370, 100, drawFormat);  
        e.Graphics.DrawString("MFG Date", f2, b1, 380, 500, drawFormat);              
        e.Graphics.DrawString(currDt, f3, b1, 350, 500, drawFormat);
    }

0 个答案:

没有答案