For the Barcode ActiveX control to be used, there is no need to place it on a form as shown here.
You can create an invisible PDF417 barcode control from any application including your DLL.
The first thing needed in order to do it is to create an object using the CreateObject
function (as shown below). After the object is created, you can use it as you want.
'Create a new instance of PDF417-ActiveX
Dim oPDF417 As Object
Set oPDF417 = CreateObject("PDF417ActiveX.PDF417Ctrl.1")
'set PDF417-ActiveX properties
oPDF417.DataToEncode = "Hello world"
'using PDF417-ActiveX
Call oPDF417.DrawPDF417ToSize(5, 5, 260, 150, dmPixels, Form1.hdc)
'destroy PDF417-ActiveX object
Set oPDF417 = Nothing
|
There are a few different ways to print a barcode from Visual Basic using our ActiveX Control.
-
Using a Visual Basic Printer object.
Printer.CurrentX = 2048
Printer.Print "BarcodeTools.com, VB Example"
'PF417-ActiveX will use the Visual Basic Printer object
Call PDF417Ctrl1.SetPrinterHDC(Printer.hdc)
'print two barcodes
Call PDF417Ctrl1.DrawPDF417ToSize(10, 10, 30, 30, dmMM)
Call PDF417Ctrl1.DrawPDF417ToSize(70, 10, 30, 30, dmMM)
Printer.EndDoc
-
Using PDF417-ActiveX methods.
'open a current printer
Call PDF417Ctrl1.BeginPrint("")
'print two PDF417 barcodes
Call PDF417Ctrl1.DrawPDF417ToSize(10, 10, 30, 30, dmMM)
Call PDF417Ctrl1.DrawPDF417ToSize(70, 10, 30, 30, dmMM)
Call PDF417Ctrl1.EndPrint
-
How to print a PDF417 barcode with a certain x-dimension?.
To find out what x-dimension is, click here.
To print a barcode with a certain x-dimension, you should correctly specify
the barcode width. You can calculate it using the GetPDF417Size method.
Private Declare Function GetDeviceCaps Lib "gdi32" _
(ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Const LOGPIXELSX = 88
Private Const LOGPIXELSY = 90
Private Sub PrintBarcode()
'Create a new instance of PDF417-ActiveX
Dim oPDF417 As Object
Set oPDF417 = CreateObject("PDF417ActiveX.PDF417Ctrl.1")
'set PDF417-ActiveX properties
oPDF417.DataToEncode = "Hello world"
oPDF417.CompactionMode = 0
'open a current printer
Call oPDF417.BeginPrint("")
'gets the printer resolution (dpi - dots per inch)
Dim dpiX As Long, dpiY As Long
dpiX = GetDeviceCaps(Printer.hdc, LOGPIXELSX)
dpiY = GetDeviceCaps(Printer.hdc, LOGPIXELSY)
'calculate the required PDF417 size (in mm) for the
'x-dimension of 0.508 mm (20 Mils)
Dim pdf417Width, pdf417Height
Call oPDF417.GetPDF417Size(0.508, dpiX, dpiY, dmMM, dmMM, _
pdf417Width, pdf417Height)
'print a PDF417 barcode
Call oPDF417.DrawPDF417ToSize(10, 10, pdf417Width, pdf417Height, _
dmMM, 0)
Call oPDF417.EndPrint
Set oPDF417 = Nothing
End Sub
|