c# - .NET Core System.Drawing.Common PrintDocument 在 Linux 上不起作用

标签 c# linux .net-core system.drawing.common

当我在 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/

相关文章:

c# - 即使 IncludeSubdirectories 设置为 false,FileSystemWatcher 也会获取子目录事件

linux - Google Chrome 中的 ERR_INVALID_SIGNED_EXCHANGE 错误

c# - 从 C# 编码结构数组

python - django 表单无法渲染到响应

linux - 为多个域配置 mod_pagespeed

c# - ILogger 显示不正确的货币符号

c# - 如何使用 VisualStudio 构建配置为 dotnet Core 项目定义 DEBUG?

c# - 为什么 `IDictionary` 不允许您在其界面中通过键或默认值轻松获取值?

javascript - 如何使用 javascript 使用来自 asp.net webservice 的 Json 数据

c# - 如何在C#中获取Windows驱动器的点击事件?