LEADTOOLS Virtual Printer (Leadtools.Printer assembly)
LEAD Technologies, Inc

Printer Constructor(PrinterInfo)

Example 





Printer information that is used to initialize the printer object.
Initializes a new instance of the class with the specified printer information and then installs the LEADTOOLS Virtual Printer to the system.
Syntax
public Printer( 
   PrinterInfo printerInfo
)
'Declaration
 
Public Function New( _
   ByVal printerInfo As PrinterInfo _
)
'Usage
 
Dim printerInfo As PrinterInfo
 
Dim instance As New Printer(printerInfo)
public Printer( 
   PrinterInfo printerInfo
)
function Printer( 
   printerInfo 
)
public:
Printer( 
   PrinterInfo^ printerInfo
)

Parameters

printerInfo
Printer information that is used to initialize the printer object.
Remarks
This overloaded constructor will automatically install LEADTOOLS printer to the system.
Example
 
Public Sub InstallPrinter()
   Try
      Dim printerName As String = "Test LEADTOOLS Printer"
      Dim printerPassword As String = "Test Password"
      If (Printer.IsLeadtoolsPrinter(printerName)) Then
         Dim tmpPrinterInfo As New PrinterInfo()
         tmpPrinterInfo.PrinterName = printerName
         tmpPrinterInfo.DriverName = printerName
         Printer.UnInstall(tmpPrinterInfo)
      End If
      Dim documentPrinterRegPath As String = "SOFTWARE\\LEAD Technologies, Inc.\\17.5\\Printer\\"
      Dim printerInfo As New PrinterInfo()
      printerInfo.MonitorName = printerName
      printerInfo.PortName = printerName
      printerInfo.DriverName = printerName
      printerInfo.ProductName = printerName
      printerInfo.PrinterName = printerName
      printerInfo.Password = printerPassword
      printerInfo.RegistryKey = documentPrinterRegPath + printerName
      printerInfo.RootDir = "C:\\LEADTOOLS 17.5\\Bin\\Common\\PrinterDriver"
      printerInfo.Url = "http://www.LeadtoolsPrinterDriver.com"
      printerInfo.PrinterExe = Application.ExecutablePath
      printerInfo.AboutString = "LEADTOOLS Printer"
      printerInfo.AboutIcon = Path.Combine(LEAD_VARS.ImagesDir, "\\RasterPro.ico")

      Printer.Install(printerInfo)

      Dim strMsg As String = String.Format("Installion {0} Completed Successfully", printerName)
      MessageBox.Show(strMsg, "LEADTOOLS Printer Demo", MessageBoxButtons.OK, MessageBoxIcon.Information)
   Catch ex As PrinterDriverException
      MessageBox.Show(String.Format("Other error: Message:{0}", ex.Message))
   End Try
End Sub

Private Sub printerTest_EmfEvent(ByVal sender As Object, ByVal e As EmfEventArgs) Handles printerTest.EmfEvent
   System.IO.File.WriteAllBytes(Path.Combine(LEAD_VARS.ImagesDir, "LEADTOOLS_IMAGE1.emf"), e.Stream.ToArray())
   Dim metaFile As New Metafile(e.Stream)

   Dim emfImage As Image = metaFile.GetThumbnailImage(metaFile.Width, metaFile.Height, Nothing, IntPtr.Zero)
   emfImage.Save(Path.Combine(LEAD_VARS.ImagesDir, "LEADTOOLS_IMAGE2.emf"))
End Sub

Private Sub printerTest_JobEvent(ByVal sender As Object, ByVal e As JobEventArgs) Handles printerTest.JobEvent
   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 with printer {1}", jobID, printerName))
   ElseIf (e.JobEventState = EventState.JobEnd) Then
      MessageBox.Show(String.Format("Job {0} was ended with printer {1}", jobID, printerName))
   Else
      printerTest.CancelPrintedJob(jobID)
   End If
End Sub

Dim WithEvents printerTest As Printer

Public Sub PrinterDriverExamples()
   printerTest = New Printer("Test LEADTOOLS Printer")
   InstallPrinter()

   If (printerTest.IsPrinterLocked()) Then
      printerTest.UnLock("Test Password")
   Else
      printerTest.Lock("Test Password")
   End If

   Dim iPAPER_USER As Integer = 256
   Dim myPrinterSpecifications As 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

   printerTest.Specifications = myPrinterSpecifications
   printerTest.UserDefaultSpecifications = myPrinterSpecifications
End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void InstallPrinter()
   {
      try
      {
         string printerName = "Test LEADTOOLS Printer";
         string printerPassword = "Test Password";
         if (Printer.IsLeadtoolsPrinter(printerName))
         {
            PrinterInfo tmpPrinterInfo = new PrinterInfo();
            tmpPrinterInfo.PrinterName = printerName;
            tmpPrinterInfo.DriverName = printerName;
            Printer.UnInstall(tmpPrinterInfo);
         }
         string documentPrinterRegPath = "SOFTWARE\\LEAD Technologies, Inc.\\17.5\\Printer\\";
         PrinterInfo printerInfo = new PrinterInfo();
         printerInfo.MonitorName = printerName;
         printerInfo.PortName = printerName;
         printerInfo.DriverName = printerName;
         printerInfo.ProductName = printerName;
         printerInfo.PrinterName = printerName;
         printerInfo.Password = printerPassword;
         printerInfo.RegistryKey = documentPrinterRegPath + printerName;
         printerInfo.RootDir = @"C:\LEADTOOLS 17.5\Bin\Common\PrinterDriver";
         printerInfo.Url = "http://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("Installion {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);
      }
   }

   Printer printer;

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

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

Printer Class
Printer Members
Overload List
Printer Class

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

Leadtools.Printer requires a Printer module license and unlock key. It is included as part of LEADTOOLS Document Imaging Enterprise. For more information, refer to: Imaging Pro/Document/Medical Features