Neodynamic Barcode Professional SDK for .NET
Barcode Professional Printing Guide

Overview
As you probably already know, most printing jobs within .NET Framework are performed by using the PrintDocument class which is part of System.Drawing.Printing namespace. The PrintDocument class is used to set the properties that describe what and where to print content such us strings, images and so on.
The main method the PrintDocument class features is Print which starts the document's printing process. After Print method is invoked, the PrintDocument raises a PrintPage event for each page to be printed. Here is where you should add your printing logic to an event handler for that event.

If your application needs to feature barcoding capabilities, it's also probably that printing documents containing barcode images are required as well.
BarcodeProfessional class features an overloaded method called DrawOnCanvas which lets you to draw the barcode image on any GDI+ Graphics object - an instance of System.Drawing.Graphics class. The PrintDocument's PrintPage event exposes a Graphics object where to paint the page content and here is where that Graphics object must be passed to the DrawOnCanvas method in order to get the barcode image printed.

This guide describes common scenarios regarding barcode printing using the PrintDocument class and Barcode Professional's DrawOnCanvas method:

How to print barcodes using PrintDocument class
This is the simplest barcode printing scenario. Here, the Graphics object exposed by PrintDocument's PrintPage event must be passed to the Barcode Professional's DrawOnCanvas method in order to get the barcode printed at the specified point (x, y).

Example
Supposing you have already set an event handler for the PrintDocument's PrintPage event, the following code inside that handler procedure will create a Barcode Professional object and will print the generated barcode at the specified location (in this case x=1in, y=1in) in the document/page. IMPORTANT: The unit of measure for the barcode location/point must be specified to BarcodeUnit property of BarcodeProfessional object. By default it is INCH

VB.NET
Private Sub printDocumentObject_PrintPage(sender As Object, e As  System.Drawing.Printing.PrintPageEventArgs)
    'Create a Barcode Professional object
    Dim bcp As New BarcodeProfessional()
    'Barcode settings
    bcp.Symbology = Symbology.Code39
    bcp.Code = "123456789"
    '...
    'Print the barcode at x=1in, y=1in using DrawOnCanvas method
    bcp.DrawOnCanvas(e.Graphics, New PointF(1, 1))
End Sub
C#
private void printDocumentObject_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    //Create a Barcode Professional object
    BarcodeProfessional bcp = new BarcodeProfessional();
    //Barcode settings
    bcp.Symbology = Symbology.Code39;
    bcp.Code = "123456789";
    //...
    //Print the barcode at x=1in, y=1in using DrawOnCanvas method
    bcp.DrawOnCanvas(e.Graphics, new PointF(1, 1));
}

How to print scaled barcodes using PrintDocument class
One version of DrawOnCanvas method lets you to print a scaled barcode image by specifying the scale parameter. For instance, if you want to scale down the original barcode to 50%, then the scale parameter must be specified as 0.5; if you want to scale up the original barcode to 200%, then the scale parameter must be specified as 2; and so on.

As the previous scenario, the Graphics object exposed by PrintDocument's PrintPage event must be passed to the Barcode Professional's DrawOnCanvas method in order to get the barcode printed at the specified point (x, y) and scaled at the specified value.

Example
Supposing you have already set an event handler for the PrintDocument's PrintPage event, the following code inside that handler procedure will create a Barcode Professional object and will print the generated barcode scaled down at 50% at the specified location (in this case x=2in, y=3in) in the document/page. IMPORTANT: The unit of measure for the barcode location/point must be specified to BarcodeUnit property of BarcodeProfessional object. By default it is INCH

VB.NET
Private Sub printDocumentObject_PrintPage(sender As Object, e As  System.Drawing.Printing.PrintPageEventArgs)
    'Create a Barcode Professional object
    Dim bcp As New BarcodeProfessional()
    'Barcode settings
    bcp.Symbology = Symbology.Code39
    bcp.Code = "123456789"
    '...
    'Print the barcode at x=2in, y=3in and scaled down at 50% using DrawOnCanvas method
    bcp.DrawOnCanvas(e.Graphics, New PointF(2, 3), 0.5F)
End Sub
C#
private void printDocumentObject_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    //Create a Barcode Professional object
    BarcodeProfessional bcp = new BarcodeProfessional();
    //Barcode settings
    bcp.Symbology = Symbology.Code39;
    bcp.Code = "123456789";
    //...
    //Print the barcode at x=2in, y=3in and scaled down at 50% using DrawOnCanvas method
    bcp.DrawOnCanvas(e.Graphics, new PointF(2, 3), 0.5f);
}

How to print barcodes that need to fit a given area using PrintDocument class
It's very common to need to print the barcode in order it fits a given area, for instance: The barcode must be printed on an area of size 1.5 inch x 1 inch.
One version of DrawOnCanvas method lets you to accomplish that by specifying the target area through barsAreaSize parameter. Keep in mind the following points about the target area:
The target area on which the barcode must be drawn
The target area on which the barcode must be drawn

Again, as in the previous scenarios, the Graphics object exposed by PrintDocument's PrintPage event must be passed to the Barcode Professional's DrawOnCanvas method in order to get the barcode printed fitting the specified area.


Example
Supposing you have already set an event handler for the PrintDocument's PrintPage event, the following code inside that handler procedure will create a Barcode Professional object and will print the generated barcode in order it fits an area of size 2 inch x 1 inch.

VB.NET
Private Sub printDocumentObject_PrintPage(sender As Object, e As  System.Drawing.Printing.PrintPageEventArgs)
    'Create a Barcode Professional object
    Dim bcp As New BarcodeProfessional()
    'Barcode settings
    bcp.Symbology = Symbology.Code39
    bcp.Code = "123456789"
    'Set Quiet Zone to zero
    bcp.QuietZoneWidth = 0
    '...
    'Print the barcode to fit an area of size 2x1in using DrawOnCanvas method
    bcp.DrawOnCanvas(e.Graphics, New PointF(0,0), New SizeF(2,1))
End Sub
C#
private void printDocumentObject_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    //Create a Barcode Professional object
    BarcodeProfessional bcp = new BarcodeProfessional();
    //Barcode settings
    bcp.Symbology = Symbology.Code39;
    bcp.Code = "123456789";
    //Set Quiet Zone to zero
    bcp.QuietZoneWidth = 0;
    //...
    //Print the barcode to fit an area of size 2x1in using DrawOnCanvas method
    bcp.DrawOnCanvas(e.Graphics, new PointF(0,0), new SizeF(2,1));
}