简体   繁体   中英

.NET Core System.Drawing.Common PrintDocument doesn't work on Linux

I have a problem with PrintDocument from System.Drawing.Common when I use this on Linux, to be more specific, the problem comes from PrintingServices.LoadPrinterSettings, which is using in PrinterSettings.Unix

here the content of the error:

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)

On Windows everything working correctly, because PrintDocument uses solution prepare for Windows.

Code:

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();

I'm using:

System.Drawing.common (4.5.1)

.NET Core 2.1

libc6-dev and libgdiplus have been installed on Linux

Linux - Debian 9

Anyone can help?

This is most likely an issue in System.Drawing.Common. The printing code on Linux has been ported from Mono and hasn't received a lot of attention.

If you can create a 'minimal repo', I think the best option is to file an issue at https://github.com/dotnet/corefx (or even better, send a PR).

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