当我在 Linux 上使用它时,System.Drawing.Common 的 PrintDocument 出现问题,更具体地说,问题来自 PrinterSettings.Unix 中使用的 PrintingServices.LoadPrinterSettings
这里是错误的内容:
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
An unhandled exception has occurred while executing the request. System.NullReferenceException: Object reference not set to an instance of an object. at System.Drawing.Printing.PrintingServices.LoadPrinterSettings(String printer, PrinterSettings settings)
在 Windows 上一切正常,因为 PrintDocument 使用 solution prepare for Windows。
代码:
PrintDocument pd = new PrintDocument();
pd.PrinterSettings.PrinterName = printerName;
pd.OriginAtMargins = true;
pd.DefaultPageSettings.Landscape = true;
pd.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
pd.PrintPage += new PrintPageEventHandler(Pd_PrintPage);
pd.Print();
我正在使用:
System.Drawing.common (4.5.1)
.NET 核心 2.1
libc6-dev 和 libgdiplus 已经安装在 Linux 上
Linux - Debian 9
有人可以帮忙吗?
最佳答案
这很可能是 System.Drawing.Common 中的一个问题。 Linux 上的打印代码是从 Mono 移植过来的,并没有受到太多关注。
如果您可以创建一个“最小存储库”,我认为最好的选择是在 https://github.com/dotnet/corefx 提交问题。 (或者更好的是,发送 PR)。
关于c# - .NET Core System.Drawing.Common PrintDocument 在 Linux 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54688383/