简体   繁体   中英

Unable to print using PrintDocument class from a Windows Docker Container using .NET 6

I am trying to print from a Windows Docker Container where I have a .NET 6 ASP.NET Api hosted. Here is my code:

private readonly PrintDocument _document;

// Some code here

public async Task PrintAsync(PrintInput input)
{
   // Some code here
   _document.PrinterSettings.PrinterName = "\\server_name\shared_printer_name";

   // Some code here
   _document.PrintPage += _document_PrintPage;

   _document.Print();
          
}

My docker container is running the following images:

FROM mcr.microsoft.com/windows/servercore:ltsc2019 AS base 
...
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
...
ENTRYPOINT ["dotnet", "App.Web.Host.dll"]

The error message that I am getting is:

The RPC server is unavailable

The host is a Windows 2019 Server and has the Service Spooler Running. The Windows container has not have a Spooler Service Running.

I was having the message:

Windows cannot connect to the printer, Operation failed with error 0x00000bcb

Then I tried:Fix Network Printer error , but it didn't help.

Also, I had tried this one: Print Spooler in Windows Containers . No success as well.

I am wondering if it is not possible to use: PrintDocument inside an application running under a Windows Docker Container. What do you guys think?

I solved it creating a Windows Service that runs printer jobs on the host server. With that I just installed the printers needed directly on the host and I call/ trigger the jobs from the ASP.NET Core API running in our docker container.

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