Take the following steps to create and run a program that prints using the LEADTOOLS printer.
Start Visual Studio .NET.
Choose File->New->Project... from the menu.
In the New Project dialog box, choose either "Visual C# Projects" or "VB Projects" in the Projects Type List, and choose "Windows Application" in the Templates List.
Type the project name as "PRINTER DRIVER" in the Project Name field, and then click OK. If desired, type a new location for your project or select a directory using the Browse button, and then click OK.
In the "Solution Explorer" window, right-click the "References" folder, and select "Add Reference..." from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and browse to Leadtools For .NET "<LEADTOOLS_INSTALLDIR>\Bin\Dotnet\Win32 " folder and select the following DLLs:
Switch to Form1 code view (right-click Form1 in the solution explorer then select View Code ) and add the following lines at the beginning of the file:
Imports System.Drawing.Imaging
Imports System.Drawing.Printing
Imports Leadtools
Imports Leadtools.Printer
using System.Drawing.Imaging;
using System.Drawing.Printing;
using Leadtools;
using Leadtools.Printer;
Declare the following private variable:
Private _printer as Printer
private Printer _printer;
Add an event handler to the Form1 Load event and code it as follows:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim printerName as string="LEADTOOLS Printer"
Dim installedPrinters As List(Of String) = New List(Of String)()
For Each printer As String In PrinterSettings.InstalledPrinters
installedPrinters.Add(printer)
Next
If Not installedPrinters.Contains(printerName) Then
Dim printerPassword as string="1234"
Dim documentPrinterRegPath As String = "SOFTWARE\\LEAD Technologies, Inc.\\Printer\\"
Dim printerInfo As New PrinterInfo()
printerInfo.MonitorName = printerName
printerInfo.PortName = printerName
printerInfo.ProductName = printerName
printerInfo.PrinterName = printerName
printerInfo.Password = printerPassword
printerInfo.RegistryKey = documentPrinterRegPath + printerName
printerInfo.RootDir = "C:\LEADTOOLS 19\Bin\Common\PrinterDriver\"
printerInfo.Url = "https://www.leadtools.com"
printerInfo.PrinterExe = Application.ExecutablePath
Printer.Install(printerInfo)
End If
_printer = New Printer(printerName)
AddHandler _printer.EmfEvent, AddressOf _printer_EmfEvent
AddHandler _printer.JobEvent, AddressOf _printer_JobEvent
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
private void Form1_Load(object sender, System.EventArgs e)
{
try
{
string printerName="LEADTOOLS Printer";
List<string> installedPrinters = new List<string>();
foreach (string printer in PrinterSettings.InstalledPrinters)
installedPrinters.Add(printer);
if (!installedPrinters.Contains(printerName))
{
string printerPassword="1234";
string documentPrinterRegPath = @"SOFTWARE\LEAD Technologies, Inc.\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:\LEADTOOLS 19\Bin\Common\PrinterDriver\";
printerInfo.Url = "https://www.leadtools.com";
printerInfo.PrinterExe = Application.ExecutablePath;
Printer.Install(printerInfo);
}
_printer=new Printer(printerName);
_printer.EmfEvent += new EventHandler<EmfEventArgs>(_printer_EmfEvent);
_printer.JobEvent += new EventHandler<JobEventArgs>(_printer_JobEvent);
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message);
}
}
Add an event handler to the Emf event and code it as follows:
Private Sub _printer_EmfEvent(ByVal sender As Object, ByVal e As EmfEventArgs)
System.IO.File.WriteAllBytes("c:\LEADTOOLS_IMAGE1.emf", e.Stream.ToArray())
Dim metaFile As New Metafile(e.Stream)
End Sub
void _printer_EmfEvent(object sender, EmfEventArgs e)
{
System.IO.File.WriteAllBytes(@"c:\1.emf", e.Stream.ToArray());
Metafile metaFile = new Metafile(e.Stream);
}
Add an event handler to the job info event and code it as follows:
Private Sub _printer_JobEvent(ByVal sender As Object, ByVal e As JobEventArgs)
Dim printerName As String = e.PrinterName
Dim jobID As Integer = e.JobID
If e.JobEventState = EventState.JobStart Then
MessageBox.Show(String.Format("Job {0} was started", jobID))
ElseIf e.JobEventState = EventState.JobEnd Then
MessageBox.Show(String.Format("Job {0} was Ended", jobID))
End If
End Sub
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",jobID));
}
else if (e.JobEventState == EventState.JobEnd)
{
MessageBox.Show(string.Format("Job {0} was Ended",jobID));
}
}
Products |
Support |
Feedback: How to Use The LEADTOOLS Virtual Printer Driver |
Introduction |
Help Version 19.0.2017.6.21
|
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.