PrintDocument.Print is slow unless user is logged in to the printing computer

有些话、适合烂在心里 提交于 2019-12-11 05:59:25

问题


I have a web application hosted on server 'A' (SA) and a web service for printing hosted on server 'B' (SB). SA creates and image that needs printing and sends it to SB. When doing this, printing is fairly slow, around fifteen seconds. However, if I log into SB using remote desktop as the user from the webconfig of the app hosted on SA, then it will print in less than two seconds. It seems as if SB is starting something up when I log into it that is making it print faster. Any idea what this could be and if there's a way that I could keep this printing fast even if I'm not logged in?

Edit: Size of the image being printed is about 20 KB.

Here's the code from of the service that is hosted on SB:

public void PrintImage(Stream printImage, string printServer, string printer)
    {
        string printerName = String.Format(@"\\{0}\{1}", printServer, printer);

        Image image = Image.FromStream(printImage);

        PrintDocument printDocument = new PrintDocument();
        PrinterSettings settings = new PrinterSettings();
        settings.PrinterName = printerName;
        printDocument.PrinterSettings = settings;

        printDocument.PrintPage += (s, e) =>
        {
            e.Graphics.DrawImage(image, 0, 0);
        };

        printDocument.Print();
    }

Thanks for taking time to read through this :)


回答1:


We found that if we created a printer mapping on SB, it would execute just as fast without a remote desktop connection.




回答2:


Note that printing from a web app (or a service) is generally unsupported. see msdn and this SO post.




回答3:


For us printing was fast as soon as we switched on the option Load User Profile in IIS.



来源:https://stackoverflow.com/questions/14220322/printdocument-print-is-slow-unless-user-is-logged-in-to-the-printing-computer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!