Implemented VirtualPrinterDriver project
This commit is contained in:
parent
f29c84821b
commit
5c87967c3f
125 changed files with 8191 additions and 0 deletions
51
Agent/VirtualPrinter.Delivery/Redirector.cs
Normal file
51
Agent/VirtualPrinter.Delivery/Redirector.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Printing;
|
||||
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace VirtualPrinter.Delivery
|
||||
{
|
||||
public static class Redirector
|
||||
{
|
||||
public static void RedirectToPrinter([NotNull]string filePath, [NotNull]string printerName)
|
||||
{
|
||||
if (filePath == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(filePath));
|
||||
}
|
||||
|
||||
if (printerName == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(printerName));
|
||||
}
|
||||
|
||||
var file = Path.GetFullPath(filePath);
|
||||
// e.g. "Dell C2665dnf Color MFP"
|
||||
using (var localSystem = new LocalPrintServer())
|
||||
{
|
||||
using (var queue = localSystem.GetPrintQueueSafe(printerName))
|
||||
{
|
||||
if (queue != null)
|
||||
{
|
||||
var ghostScriptRedirector = new GhostScriptRedirector(queue);
|
||||
ghostScriptRedirector.Redirect(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[CanBeNull]
|
||||
private static PrintQueue GetPrintQueueSafe(this PrintServer server, string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return server.GetPrintQueue(name);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue