Skip to content

Commit

Permalink
update !
Browse files Browse the repository at this point in the history
  • Loading branch information
looksharp committed Mar 7, 2021
1 parent f63a98d commit b94ec03
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/ScanX.Core/PrinterClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace ScanX.Core
Expand All @@ -26,6 +27,7 @@ public PrinterClient(ILogger<PrinterClient> logger)
_defaultPrinterSettings = new PrinterSettings();

_printDocument = new PrintDocument();

_printDocument.PrintPage += OnPrintingPage;
}

Expand All @@ -36,15 +38,23 @@ public string GetDefaultPrinter()

public void Print(byte[] imageToPrint,PrintSettings settings)
{

var defaultPrinterSettings = new PrinterSettings();
var defaultPrinterName = defaultPrinterSettings.PrinterName;

SetDefaultPrinter(settings.PrinterName);

var zebraPrinterSettings = new PrinterSettings();

_ms = new MemoryStream();
_ms.Write(imageToPrint, 0, imageToPrint.Length);
_currentSettings = settings;
var margin = _currentSettings.Margin;

_printDocument.DefaultPageSettings.PrinterSettings.PrinterName = settings.PrinterName;
_printDocument.DefaultPageSettings.Margins = new Margins(margin.Left,margin.Right,margin.Top,margin.Bottom);

_printDocument.PrinterSettings = zebraPrinterSettings;
_printDocument.DefaultPageSettings.Margins = new Margins(margin.Left, margin.Right, margin.Top, margin.Bottom);
_printDocument.Print();

SetDefaultPrinter(defaultPrinterName);
}

private void OnPrintingPage(object sender, PrintPageEventArgs e)
Expand Down Expand Up @@ -75,6 +85,9 @@ private void OnPrintingPage(object sender, PrintPageEventArgs e)

}

[DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetDefaultPrinter(string Name);

public void Dispose()
{

Expand Down

0 comments on commit b94ec03

Please sign in to comment.