简体   繁体   中英

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

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 :)

我们发现,如果我们在SB上创建打印机映射,则无需远程桌面连接即可执行相同的速度。

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

对我们来说,只要在IIS中打开“ Load User Profile ”选项,打印速度就会很快。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM