【问题标题】:PrintDocument issues with Windows Server 2008 R2 Standard 64-bitWindows Server 2008 R2 Standard 64 位的 PrintDocument 问题
【发布时间】:2014-09-12 10:08:54
【问题描述】:

似乎在 Windows 7 64 位 (SP1) 机器上尝试使用 System.Drawing.Printing.PrintDocument 命名空间时效果很好。但是在 Server 2008 R2 64 位 (SP1) 机器上尝试相同的代码,它只是挂在代码中。不抛出异常等...

这是我的代码的 sn-p...

private bool PrintTIF(string sPrinter, string sFile)
{
    try
    {
        //Open file for printing
        WriteEvent(105, "Opening the file for printing using streamreader...", CustomLogTool.EventLogEntryTypeExtentions.Debug);
        m_PrinterFile = new StreamReader(sFile);

        //Set the document name
        WriteEvent(105, "Set the document name.", CustomLogTool.EventLogEntryTypeExtentions.Debug);
        m_Printer.DocumentName = Path.GetFileName(sFile);

        //Print file
        WriteEvent(105, "Sending the file to the printer...", CustomLogTool.EventLogEntryTypeExtentions.Debug);
        m_Printer.Print();
        m_PrinterFilesPrinting.Add(new PrintInfo(sFile, null, sPrinter));

        //Close file
        WriteEvent(105, "Closing the file and destorying the streamreader object.", CustomLogTool.EventLogEntryTypeExtentions.Debug);
        m_PrinterFile.Close();

        //Success
        return true;
    }
    catch (Exception ex)
    {
        try { m_PrinterFile.Close(); }
        catch { }
        WriteEvent(201, ex.Message, CustomLogTool.EventLogEntryTypeExtentions.Debug);

        return false;
    }
}

我收到的日志事件最多为“将文件发送到打印机...”。我什么也没得到,我希望在异常中收到我的错误 201 消息。但我什么也得不到。就好像程序挂了一样。我猜这是由于从 Win7 (SP1) 更改为 Server2008R2(SP1) 造成的。有什么想法吗?

【问题讨论】:

  • 从不、尝试从服务打印。您看不到打印机驱动程序警报。
  • 我的应用程序的重点是从服务打印...为什么我不能将那些“打印机驱动程序警报”包装到事件日志条目中?您能否详细说明“打印机驱动程序警报”?它们是什么,我怎样才能看到它们或访问它们等等......任何东西......

标签: c# windows-server-2008-r2


【解决方案1】:

解决方案: 我弄清楚我的问题是什么。这与我一直选择错误的打印机有关!这么简单的事情浪费了很多时间,但它确实让我走上了一条以不同方式调试它的道路。在我开始使用正确的打印机之后,我发现我的下一个问题是一个 TIFF 文件,它不是一个实际的 TIFF 文件。它恰好是我在测试目录中忘记通过的 0 字节测试文件。

我调试这些服务打印机问​​题的新方法: 找出发生了什么的最好方法是离开“服务领域”一段时间。将其编译为 Debug 构建,这样您就可以将其作为控制台应用程序运行。将其构建为 Release 构建需要您将其作为服务运行,并且不允许您手动运行它。当我将它构建为调试版本时,我从目录在服务器上运行它,然后弹出一个 Windows 对话框......它问我要将文件保存为什么。在我发现它是默认的“Microsoft XPS Document Writer”打印机后不久!

然后我进去并将打印机更改为我想要的打印机(通过代码)...

PrintDocument pd = new PrintDocument();
pc = new StandardPrintController();
pd.PrintController = pc;
// Yadda Yadda Yadda...
pd.PrinterSettings.PrinterName = "My Printer Name";

希望它可以帮助其他人并节省他们一些时间!祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-12
    • 2014-11-25
    • 1970-01-01
    • 1970-01-01
    • 2012-07-29
    • 1970-01-01
    相关资源
    最近更新 更多