【问题标题】:.NET Core System.Drawing.Common PrintDocument doesn't work on Linux.NET Core System.Drawing.Common PrintDocument 在 Linux 上不起作用
【发布时间】:2019-02-14 10:36:15
【问题描述】:

我在 Linux 上使用 System.Drawing.Common 的 PrintDocument 时遇到问题,更具体地说,问题来自在 PrinterSettings.Unix 中使用的 PrintingServices.LoadPrinterSettings

这里是错误的内容:

Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
执行请求时发生未处理的异常。 System.NullReferenceException:对象引用未设置为实例 的一个对象。在 System.Drawing.Printing.PrintingServices.LoadPrinterSettings(字符串 打印机、PrinterSettings 设置)

在 Windows 上一切正常,因为 PrintDocument 使用为 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 Core 2.1

Linux 上已经安装了 libc6-dev 和 libgdiplus

Linux - Debian 9

有人可以帮忙吗?

【问题讨论】:

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


    【解决方案1】:

    这很可能是 System.Drawing.Common 中的问题。 Linux 上的打印代码是从 Mono 移植过来的,没有受到太多关注。

    如果您可以创建“最小回购”,我认为最好的选择是在 https://github.com/dotnet/corefx 提交问题(或者更好的是,发送 PR)。

    【讨论】:

    • 感谢您的回答,我向dotnet corefx报告了一个问题
    • 此问题是否已为您解决。因为我也遇到了同样的问题。请指导我。我可以看到问题仍处于打开状态“github.com/dotnet/corefx/issues/36102”。
    猜你喜欢
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-21
    • 2018-08-28
    • 1970-01-01
    • 2020-03-26
    • 2021-10-22
    • 1970-01-01
    相关资源
    最近更新 更多