public void Dispose()
The Printer class implements the System.IDisposable interface, it is recommended that you follow the standard .NET dispose pattern when using the Printer class. For more information, refer to the System.IDisposable interface documentation in MSDN.
using Leadtools.Printer;
using Leadtools;
public void PrinterDriverExamples()
{
InstallPrinter();
printer = new Printer("Test LEADTOOLS Printer ");
if (printer.IsPrinterLocked())
{
printer.UnLock("Test Password");
}
else
{
printer.Lock("Test Password");
}
int iPAPER_USER = 256;
PrinterSpecifications myPrinterSpecifications = new PrinterSpecifications();
myPrinterSpecifications.PaperID = iPAPER_USER + 200;
myPrinterSpecifications.PaperSizeName = "Custom Paper Name";
myPrinterSpecifications.PaperHeight = 11;
myPrinterSpecifications.PaperWidth = 8;
myPrinterSpecifications.DimensionsInInches = true;
myPrinterSpecifications.PortraitOrient = true;
myPrinterSpecifications.MarginsPrinter = "Margins Printer Name";
myPrinterSpecifications.PrintQuality = 300;
myPrinterSpecifications.YResolution = 300;
printer.Specifications = myPrinterSpecifications;
printer.UserDefaultSpecifications = myPrinterSpecifications;
printer.EmfEvent += new EventHandler<EmfEventArgs>(printer_EmfEvent);
printer.JobEvent += new EventHandler<JobEventArgs>(printer_JobEvent);
}
Printer printer;
public void InstallPrinter()
{
try
{
string printerName = "Test LEADTOOLS Printer";
string printerPassword = "Test Password";
if (Printer.IsLeadtoolsPrinter(printerName))
{
PrinterInfo tmpPrinterInfo = new PrinterInfo();
tmpPrinterInfo.PrinterName = printerName;
Printer.UnInstall(tmpPrinterInfo);
}
string documentPrinterRegPath = "SOFTWARE\\LEAD Technologies, Inc.\\22\\Printer\\";
PrinterInfo printerInfo = new PrinterInfo();
printerInfo.MonitorName = printerName;
printerInfo.PortName = printerName;
printerInfo.ProductName = printerName;
printerInfo.PrinterName = printerName;
printerInfo.Password = printerPassword;
printerInfo.RegistryKey = documentPrinterRegPath + printerName;
printerInfo.RootDir = @"C:\LEADTOOLS22\Bin\Common\PrinterDriver";
printerInfo.Url = "https://www.leadtools.com";
printerInfo.PrinterExe = Application.ExecutablePath;
printerInfo.AboutString = "LEADTOOLS Printer";
printerInfo.AboutIcon = Path.Combine(LEAD_VARS.ImagesDir, "RasterPro.ico");
Printer.Install(printerInfo);
string strMsg = string.Format("Installation {0} Completed Successfully", printerName);
MessageBox.Show(strMsg, "LEADTOOLS Printer Demo", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (PrinterDriverException ex)
{
MessageBox.Show(string.Format("Other error: Message:{0}", ex.Message));
}
}
void printer_EmfEvent(object sender, EmfEventArgs e)
{
System.IO.File.WriteAllBytes(Path.Combine(LEAD_VARS.ImagesDir, @"LEADTOOLS_IMAGE1.emf"), e.Stream.ToArray());
Metafile metaFile = new Metafile(e.Stream);
Image emfImage = metaFile.GetThumbnailImage(metaFile.Width, metaFile.Height, null, IntPtr.Zero);
emfImage.Save(Path.Combine(LEAD_VARS.ImagesDir, @"LEADTOOLS_IMAGE2.emf"));
}
void printer_JobEvent(object sender, JobEventArgs e)
{
string printerName = e.PrinterName;
int jobID = e.JobID;
if (e.JobEventState == EventState.JobStart)
{
MessageBox.Show(string.Format("Job {0} was started with printer {1}", jobID, printerName));
}
else if (e.JobEventState == EventState.JobEnd)
{
MessageBox.Show(string.Format("Job {0} was ended with printer {1}", jobID, printerName));
}
else
{
printer.CancelPrintedJob(jobID);
}
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
}