Implemented VirtualPrinterDriver project

This commit is contained in:
Marco Batzinger 2020-10-19 17:44:50 +02:00
parent f29c84821b
commit 5c87967c3f
125 changed files with 8191 additions and 0 deletions

View 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;
}
}
}
}