Products | Support | Email a link to this topic. | Send comments on this topic. | Back to Introduction | Help Version 19.0.8.29
|
[Visual Basic]
Imports System
Imports System.Text
Imports System.Diagnostics
Imports System.Drawing.Imaging
Imports System.Windows.Forms
Imports Leadtools
Imports Leadtools.Printer
Imports Leadtools.Codecs
Imports Leadtools.Forms.DocumentWriters
[C#]
using System;
using System.Text;
using System.Diagnostics;
using System.Drawing.Imaging;
using System.Windows.Forms;
using Leadtools;
using Leadtools.Printer;
using Leadtools.Codecs;
using Leadtools.Forms.DocumentWriters;
[Visual Basic]
Private WithEvents _printer as Printer
[C#]
Printer _printer;
[Visual Basic]
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Try
Dim printerName As String = "LEADTOOLS Printer"
If (Not Printer.IsLeadtoolsPrinter(printerName)) Then
Dim printerPassword As String = "1234"
Dim documentPrinterRegPath As String = "SOFTWARE\LEAD Technologies, Inc.\Printer\"
Dim printerInfo As PrinterInfo = New PrinterInfo()
printerInfo.DriverName = 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)
_printer.EnableNetworkPrinting = True
AddHandler _printer.EmfEvent, AddressOf Of EmfEventArgs
AddHandler _printer.JobEvent, AddressOf Of JobEventArgs
Catch ex As Exception
MessageBox.Show(Me, ex.Message)
End Try
End Sub
[C#]
private void Form1_Load(object sender, System.EventArgs e)
{
try
{
string printerName = "LEADTOOLS Printer";
if (!Printer.IsLeadtoolsPrinter(printerName))
{
string printerPassword = "1234";
string documentPrinterRegPath = @"SOFTWARE\LEAD Technologies, Inc.\Printer\";
PrinterInfo printerInfo = new PrinterInfo();
printerInfo.DriverName = 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.EnableNetworkPrinting = true;
_printer.EmfEvent += new EventHandler<EmfEventArgs>(_printer_EmfEvent);
_printer.JobEvent += new EventHandler<JobEventArgs>(_printer_JobEvent);
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message);
}
}
[Visual Basic]
Private Sub printerTest_EmfEvent(ByVal sender As Object, ByVal e As EmfEventArgs) Handles printerTest.EmfEvent
System.IO.File.WriteAllBytes("c:\LEADTOOLS_IMAGE1.emf", e.Stream.ToArray())
Dim metaFile As New Metafile(e.Stream)
End Sub
[C#]
void _printer_EmfEvent(object sender, EmfEventArgs e)
{
System.IO.File.WriteAllBytes(@"c:\LEADTOOLS_IMAGE1.emf", e.Stream.ToArray());
Metafile metaFile = new Metafile(e.Stream);
}
[Visual Basic]
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
Try
'Data is a string. The user specifies the data to be sent from the client machine
'check user demo for more info
Dim enc As Encoding = Encoding.ASCII
Dim strData As String = enc.GetString(_printer.RemoteData.UserData)
MessageBox.Show(String.Format("Job {0} was started with remote data " & strData, jobID))
Catch ex As Exception
MessageBox.Show(ex.Message)
Throw
End Try
Else If e.JobEventState = EventState.JobEnd Then
MessageBox.Show(String.Format("Job {0} was Ended", jobID))
Process.Start("mspaint", "c:\LEADTOOLS_IMAGE1.emf")
End If
End Sub
[C#]
void _printer_JobEvent(object sender, JobEventArgs e)
{
string printerName = e.PrinterName;
int jobID = e.JobID;
if (e.JobEventState == EventState.JobStart)
{
try
{
// Data is a string. The user specifies the data to be sent from the client machine
// check user demo for more info
Encoding enc = Encoding.ASCII;
String strData = enc.GetString(_printer.RemoteData.UserData);
MessageBox.Show(string.Format("Job {0} was started with remote data " + strData, jobID));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
throw;
}
}
else if (e.JobEventState == EventState.JobEnd)
{
MessageBox.Show(string.Format("Job 0 was Ended", jobID));
Process.Start("mspaint", @"c:\LEADTOOLS_IMAGE1.emf");
}
}
Note: when the job event is received, the _printer.RemoteDate will return the data sent from the remote machine, this data will be available until demo receives EventState.JobEnd _printer.RemoteDate will contain row data, this raw data will be specified by the user.