【问题标题】:Printing Raw Data in Terminal Server在终端服务器中打印原始数据
【发布时间】:2011-12-03 21:31:23
【问题描述】:

这是场景:

  • 我有一个带有终端服务器的 Windows Server 2008(没有域控制器,没有加入域)
  • 我有一台更新了 Windows XP SP3 的客户端计算机(.NET 3.0 SP1 和 .NET 4.0)
  • 我正在使用 Embarcadero C++Builder (BCB6)
  • 我有票据打印机(热敏打印机、POS 打印机、Epson、Zebra 等)

当我连接到终端服务器时,打印机工作正常。我测试了打印测试页。

当我使用我的软件在本地计算机上的终端服务器中发送原始数据时,我收到此错误:

Windows Presentation Foundation terminal server print W has encountered a
problem and needs to close. We are sorry for the inconvenience.

我听从了support page 的建议,但没有运气。

我以前直接打印到 LPT1:,但在 Windows Server 2008 中,这项工作变得越来越难,所以我们必须改变打印到这种打印机的方式。

这是我正在使用的代码。我在本地测试过,效果很好,但是在终端服务器上就不行了:

bool TForm1::RawDataToPrinter(char* szPrinterName, char* lpData, unsigned int dwCount )
{
    int BytesWritten;
    HANDLE hPrinter;
    TDocInfo1 DocInfo;
    bool bStatus = false;
    int dwJob = 0;
    unsigned long dwBytesWritten = 0;

    // Open a handle to the printer.
    bStatus = OpenPrinter( szPrinterName, &hPrinter, NULL );

    if( bStatus )
    {
        // Fill in the structure with info about this "document."
        DocInfo.pDocName = "My Document";
        DocInfo.pOutputFile = NULL;
        DocInfo.pDatatype = "RAW";

        // to indicate that the application will be sending document data to the printer.
        dwJob = StartDocPrinter( hPrinter, 1, (LPBYTE)&DocInfo );

        if ( dwJob > 0 )
        {
            // Start a page.
            bStatus = StartPagePrinter( hPrinter );
            bStatus = true;

            if( bStatus )
            {
                // Send the data to the printer.
                bStatus = WritePrinter( hPrinter, lpData, dwCount, &dwBytesWritten );
                EndPagePrinter ( hPrinter );
            }

            // Inform the spooler that the document is ending.
            EndDocPrinter( hPrinter );
        }
        // Close the printer handle.
        ClosePrinter( hPrinter );
    }
    // Check to see if correct number of bytes were written.
    if (!bStatus || (dwBytesWritten != dwCount))
        bStatus = false;
    else
        bStatus = true;

    return bStatus;
}

我从 Microsoft 支持中的示例复制了此代码。我也尝试将“RAW”更改为“TEXT”,但我得到了同样的错误。

我试过这段代码,因为它使用 GDI 来打印:

long pageline;

char prueba[255];

Printer()->SetPrinter(ListBox1->Items->Strings[ListBox1->ItemIndex].c_str(), "WINSPOOL", "", NULL);
Printer()->BeginDoc();

pageline = 0;
while(pageline < Memo1->Lines->Count)
{
    Printer()->Canvas->TextOut(10, (10 + Printer()->Canvas->TextHeight("Hi! There")) * pageline, Memo1->Lines->Strings[pageline]);
    pageline++;
}

Printer()->EndDoc();

这是我在 Embarcadero 论坛上找到的一个示例。

我还验证了 TsWpfWrp.exe。我尝试用服务器中的替换它,但它什么也不做,不发送错误,也不会发送任何数据。

还有其他方法可以做到这一点吗?我的代码有问题吗?

感谢任何帮助或见解。

【问题讨论】:

    标签: c++ printing terminal-services


    【解决方案1】:

    我发现了问题,是 Easy Print 驱动程序,它在 RAW 模式下期望 XPS 规范,但我只发送文本。

    我禁用了 Easy Print 以将打印机置于 Fallback 模式(类似的),这是终端服务器的位置,它首先查找已安装的驱动程序,然后查找 Easy Print(这可以在高级选项中的打印机)。

    现在可以了,谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-09
      相关资源
      最近更新 更多