Internet Printing Protocol (IPP) support with the LEADTOOLS Virtual Printer

Take the following steps to create and run a program that prints using the LEADTOOLS Network printer.

1.   Make sure you have IIS installed on the machine correctly. And make sure the LEADTOOLS virtual printer web service is configured correctly.

2.   Start Visual Studio .NET.

3.   Choose File-> New->Project... from the menu.

4.   In the New Project dialog box, choose either "Visual C# Projects" or "Visual Basic Projects" in the Projects Type List, and choose "Windows Application" in the Templates List.

5.   Type the project name as "LEADTOOLS IPP Demo" 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.

6.   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 the LEADTOOLS For .NET "<LEADTOOLS_INSTALLDIR>\Bin\Dotnet4\Win32" folder and select the following DLLs:

7.   Switch to Form1 code view (right-click Form1 in the solution explorer and then select View Code) and add the following lines at the beginning of the file:

Imports System 
Imports System.Drawing.Imaging 
Imports System.Text 
Imports System.Diagnostics 
Imports System.Windows.Forms 
Imports Leadtools 
Imports Leadtools.Printer 
Imports Leadtools.Codecs 
Imports Leadtools.Forms.DocumentWriters 

using System; 
using System.Drawing.Imaging; 
using System.Text; 
using System.Diagnostics; 
using System.Windows.Forms; 
using Leadtools; 
using Leadtools.Printer; 
using Leadtools.Codecs; 
using Leadtools.Forms.DocumentWriters; 

8.   Declare the following private variable:

Private WithEvents _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 Object, ByVal e As System.EventArgs) 
      Dim printerName As String = "LEADTOOLS Printer" 
      If (NotPrinter.IsLeadtoolsPrinter(printerName))Then 
         Dim documentPrinterRegPath As String = "SOFTWARE\LEAD Technologies, Inc.\Printer\" 
         Dim printerInfo As PrinterInfo = New PrinterInfo() 
         printerInfo.ProductName = printerName 
         printerInfo.PrinterName = printerName 
         printerInfo.RegistryKey = documentPrinterRegPath & printerName 
         printerInfo.RootDir = "C:\LEADTOOLS 19\Bin\Common\PrinterDriver\" 
         printerInfo.Url = 
         printerInfo.PrinterExe = Application.ExecutablePath 
      End If 
     _printer = New Printer(printerName) 
     _printer.EnableNetworkPrinting = True 
     _printer.EnableInternetPrinting = True 
  Catch ex As Exception 
     MessageBox.Show(Me, ex.Message) 
  End Try 
End Sub  

private void Form1_Load(object sender, System.EventArgs e) 
      string printerName = "LEADTOOLS Printer"; 
      if (!Printer.IsLeadtoolsPrinter(printerName)) 
         string documentPrinterRegPath = @"SOFTWARE\LEAD Technologies, Inc.\Printer\"; 
         PrinterInfo printerInfo = new PrinterInfo(); 
         printerInfo.ProductName = printerName; 
         printerInfo.PrinterName = printerName; 
         printerInfo.RegistryKey = documentPrinterRegPath + printerName; 
         printerInfo.RootDir = @"C:\LEADTOOLS 19\Bin\Common\PrinterDriver\"; 
         printerInfo.Url =; 
         printerInfo.PrinterExe = Application.ExecutablePath; 
      _printer = new Printer(printerName); 
      _printer.EnableNetworkPrinting = true; 
      _printer.EnableInternetPrinting = true; 
      _printer.EmfEvent += new EventHandler<EmfEventArgs>(_printer_EmfEvent); 
      _printer.JobEvent += new EventHandler<JobEventArgs>(_printer_JobEvent); 
   catch (Exception ex) 
      MessageBox.Show(this, ex.Message); 

10. Add an event handler to the Emf event and code it as follows:

Private Sub printerTest_EmfEvent(ByVal sender As Object, ByVal e As EmfEventArgs)Handles _printer.EmfEvent 
   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:\LEADTOOLS_IMAGE1.emf", e.Stream.ToArray()); 
   Metafile metaFile = new Metafile(e.Stream); 

11. 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) Handles _printer.JobEvent 
   Dim jobID As Integer = e.JobID 
   If e.JobEventState = EventState.JobStart Then 
         MessageBox.Show(String.Format("Job ID: {0}", jobID)) 
      Catch ex As Exception 
      End Try 
   ElseIf 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 

void _printer_JobEvent(object sender, JobEventArgs e) 
   int jobID = e.JobID; 
   if (e.JobEventState == EventState.JobStart) 
      {    MessageBox.Show(string.Format("Job ID: {0}", jobID)); 
      catch (Exception ex) 
   else if (e.JobEventState == EventState.JobEnd) 
      MessageBox.Show(string.Format("Job 0 was Ended", jobID)); 
      Process.Start("mspaint", @"c:\LEADTOOLS_IMAGE1.emf"); 

12. Make sure to share the new printer after installing it.

13. Build, and Run the program to test it.

Note1: to Configure Internet printing on a computer running Windows Server 2008, perform the following steps:

1- Run the Server Manager.

2- Select Add Roles.

3- Select the following roles:

4- In the Roles Services, Select the following services:

5- Complete the Installation.

Note2: To install the printer driver on a client computer, perform the following steps:

1- Open SERVER_IP/printers in Internet Explorer:


2- When you click “Test Printer” (the Installed Test Printer’s Name), the selected printer page will open.

3- Click the Connect link.

4- Complete the Installation.

Programming with the Virtual Printer Driver Class

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Imaging, Medical, and Document