简体   繁体   English

System.Drawing.Printing.PrintDocument慢

[英]System.Drawing.Printing.PrintDocument Is Slow

I have a application that needs to print a Metafile. 我有一个需要打印图元文件的应用程序。 The Metafile is a rendering of a SSRS report. 图元文件是SSRS报告的呈现。 I am using the System.Drawing.Printing.PrintDocument class to print the report. 我正在使用System.Drawing.Printing.PrintDocument类来打印报告。 Here is the my class that is doing the printing: 这是我做印刷的班级:

public class EMFPrinter
{
    private IList<Stream> m_streams;
    private string printerName;
    private int m_currentPageIndex;

    public EMFPrinter(IList<Stream> reportstreams, string printer)
    {
        m_streams = reportstreams;
        printerName = printer;
        m_currentPageIndex = 0;
    }

    public void Print()
    {
        PrintDocument printDoc = new PrintDocument();
        printDoc.PrinterSettings.PrinterName = printerName;
        printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
        printDoc.Print();
    }

    private void PrintPage(object sender, PrintPageEventArgs ev)
    {
        Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);
        ev.Graphics.DrawImage(pageImage, ev.PageBounds);
        m_currentPageIndex++;
        ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
    }
}

If I run this from my desktop (Windows 8) it runs great. 如果从台式机(Windows 8)运行此程序,它将运行良好。 If I try to run it from the server that it needs to run on (Windows Server 2008 R2) it works great for some printers, however the printer that I need it to print on is a HP LaserJet 1536dnf, and when I try to print to it from the server it literally takes about five minutes to print. 如果我尝试从需要在其上运行的服务器(Windows Server 2008 R2)上运行它,则它对于某些打印机非常适用,但是我需要在其上进行打印的打印机是HP LaserJet 1536dnf,并且在我尝试进行打印时从服务器到它的打印时间大约为五分钟。 If I try to print to that same printer from my desktop it prints immediately. 如果我尝试从台式机打印到同一台打印机,它将立即打印。 If I try to print to that printer from the server from some application (like paint) then it prints immediately. 如果我尝试通过某些应用程序(例如油漆)从服务器打印到该打印机,则它将立即打印。

What could be causing my code to take so long to print to this printer from the server? 是什么导致我的代码需要很长时间才能从服务器打印到该打印机上?

This ended up being a print driver issue. 最终成为打印驱动程序问题。 After fighting with this for awhile I downloaded the latest print driver and installed it on the server. 与之抗争了一段时间之后,我下载了最新的打印驱动程序并将其安装在服务器上。 I then installed the printer on the server using the new print driver and setting it up as a local printer with a ip address port. 然后,我使用新的打印驱动程序将打印机安装在服务器上,并将其设置为具有ip地址端口的本地打印机。 This fixed the issue. 这解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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