ByteScout Barcode Suite - VB.NET - Print labels with barcode sdk - ByteScout

ByteScout Barcode Suite – VB.NET – Print labels with barcode sdk

  • Home
  • /
  • Articles
  • /
  • ByteScout Barcode Suite – VB.NET – Print labels with barcode sdk

How to print labels with barcode sdk in VB.NET with ByteScout Barcode Suite

Learn to print labels with barcode sdk in VB.NET

Print labels with barcode sdk is simple to apply in VB.NET if you use these source codes below. ByteScout Barcode Suite is the bundle that privides 3 SDK products to generate barcodes (Barcode SDK), read barcodes (Barcode Reaer SDK) and read and write spreadsheets (Spreadsheet SDK). It can be applied to print labels with barcode sdk using VB.NET.

The SDK samples given below describe how to quickly make your application do print labels with barcode sdk in VB.NET with the help of ByteScout Barcode Suite. IF you want to implement the functionality, just copy and paste this code for VB.NET below into your code editor with your app, compile and run your application. Check VB.NET sample code samples to see if they respond to your needs and requirements for the project.

You can download free trial version of ByteScout Barcode Suite from our website with this and other source code samples for VB.NET.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

Form1.Designer.vb
      
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Partial Class Form1 Inherits System.Windows.Forms.Form 'Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) Try If disposing AndAlso components IsNot Nothing Then components.Dispose() End If Finally MyBase.Dispose(disposing) End Try End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1)) Me.buttonPrint = New System.Windows.Forms.Button() Me.PrintPreviewDialog1 = New System.Windows.Forms.PrintPreviewDialog() Me.PrintDocument1 = New System.Drawing.Printing.PrintDocument() Me.PrintDialog1 = New System.Windows.Forms.PrintDialog() Me.SuspendLayout() ' 'buttonPrint ' Me.buttonPrint.Location = New System.Drawing.Point(12, 12) Me.buttonPrint.Name = "buttonPrint" Me.buttonPrint.Size = New System.Drawing.Size(260, 57) Me.buttonPrint.TabIndex = 1 Me.buttonPrint.Text = "Draw And Print Cards" Me.buttonPrint.UseVisualStyleBackColor = True ' 'PrintPreviewDialog1 ' Me.PrintPreviewDialog1.AutoScrollMargin = New System.Drawing.Size(0, 0) Me.PrintPreviewDialog1.AutoScrollMinSize = New System.Drawing.Size(0, 0) Me.PrintPreviewDialog1.ClientSize = New System.Drawing.Size(400, 300) Me.PrintPreviewDialog1.Document = Me.PrintDocument1 Me.PrintPreviewDialog1.Enabled = True Me.PrintPreviewDialog1.Icon = CType(resources.GetObject("PrintPreviewDialog1.Icon"), System.Drawing.Icon) Me.PrintPreviewDialog1.Name = "PrintPreviewDialog1" Me.PrintPreviewDialog1.Visible = False ' 'PrintDocument1 ' ' 'PrintDialog1 ' Me.PrintDialog1.Document = Me.PrintDocument1 Me.PrintDialog1.UseEXDialog = True ' 'Form1 ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(284, 149) Me.Controls.Add(Me.buttonPrint) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub Private WithEvents buttonPrint As System.Windows.Forms.Button Friend WithEvents PrintPreviewDialog1 As System.Windows.Forms.PrintPreviewDialog Friend WithEvents PrintDocument1 As System.Drawing.Printing.PrintDocument Friend WithEvents PrintDialog1 As System.Windows.Forms.PrintDialog End Class

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Barcode Suite Home Page

Explore ByteScout Barcode Suite Documentation

Explore Samples

Sign Up for ByteScout Barcode Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Form1.vb
      
Imports System.Drawing.Drawing2D Imports Bytescout.BarCode Public Class Form1 Dim PaperSize As SizeF = New SizeF(5.5F, 8.75F) ' 5.5 x 8.75 inches Const PrintingResolution As Integer = 300 ' 300 dots per inch Public Sub New() ' This call is required by the designer. InitializeComponent() ' Make the print preview dialog larger by default PrintPreviewDialog1.MinimumSize = New Size(800, 600) End Sub Private Sub buttonPrint_Click(sender As Object, e As EventArgs) Handles buttonPrint.Click ' Show print setup dialog, then print preview If PrintDialog1.ShowDialog() = DialogResult.OK Then PrintPreviewDialog1.ShowDialog() End If End Sub Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage ' Draw page on the printer device context Dim pageBitmap = DrawPage() e.Graphics.DrawImage(pageBitmap, 0, 0) End Sub ' Draw cards on a bitmap of custom size Private Function DrawPage() As Bitmap Dim cardSize As SizeF = New SizeF(PaperSize.Width / 4, PaperSize.Height / 4) ' 4 x 4 cards on a page ' Prepare constant and variable labels Dim strBrand = "CJ SHOES" Dim strModel = "ARTHUR-1N" Dim strColor = "BLK" Dim shoeSizeStart As Single = 5.5F Dim shoeSizeStep As Single = 0.5F Dim barcodeStartValue As Long = 4611030000 Dim barcodeValueStep As Integer = 1 ' Prepare fonts Dim font1 = New Font("Arial", 0.12F, GraphicsUnit.Inch) Dim font2 = New Font("Arial", 0.1F, GraphicsUnit.Inch) Dim font3 = New Font("Arial", 0.09F, GraphicsUnit.Inch) Dim font4 = New Font("Arial", 0.15F, GraphicsUnit.Inch) ' Prepare barcode generator Dim barcode = New Barcode("demo", "demo") barcode.Symbology = SymbologyType.I2of5 barcode.NarrowBarWidth = 2 barcode.DrawCaption = False Dim cardIndex = 0 ' Create bitmap for the page Dim pageBitmap = New Bitmap(CType((PaperSize.Width * PrintingResolution), Integer), CType((PaperSize.Height * PrintingResolution), Integer)) pageBitmap.SetResolution(PrintingResolution, PrintingResolution) Using pageCanvas As Graphics = Graphics.FromImage(pageBitmap) pageCanvas.InterpolationMode = InterpolationMode.HighQualityBicubic pageCanvas.CompositingQuality = CompositingQuality.HighQuality ' Setup page units to inches pageCanvas.PageUnit = GraphicsUnit.Inch ' Fill background with white color pageCanvas.Clear(Color.White) ' Draw cards For row As Integer = 0 To 3 For column As Integer = 0 To 3 ' Create bitmap for card Dim cardBitmap = New Bitmap(CType((cardSize.Width * PrintingResolution), Integer), CType((cardSize.Height * PrintingResolution), Integer)) cardBitmap.SetResolution(PrintingResolution, PrintingResolution) Using cardCanvas As Graphics = Graphics.FromImage(cardBitmap) ' Setup page units to inches cardCanvas.PageUnit = GraphicsUnit.Inch ' Setup drawing quality cardCanvas.SmoothingMode = SmoothingMode.HighQuality cardCanvas.InterpolationMode = InterpolationMode.HighQualityBicubic cardCanvas.CompositingQuality = CompositingQuality.HighQuality Dim stringFormat = New StringFormat() stringFormat.Alignment = StringAlignment.Center ' Draw static labels cardCanvas.DrawString(strBrand, font1, Brushes.Black, cardSize.Width / 2, 0.1F, stringFormat) cardCanvas.DrawString(strModel, font2, Brushes.Black, cardSize.Width / 2, 0.4F, stringFormat) cardCanvas.DrawString(strColor, font1, Brushes.Black, cardSize.Width / 2, 0.7F, stringFormat) ' Generate barcode image barcode.Value = (barcodeStartValue + cardIndex * barcodeValueStep).ToString() barcode.PreserveMinReadableSize = False barcode.ResolutionX = PrintingResolution barcode.ResolutionY = PrintingResolution barcode.FitInto(cardSize.Width, 0.5F, UnitOfMeasure.Inch) Dim barcodeImage = barcode.GetImage() ' Draw barcode cardCanvas.DrawImage(barcodeImage, 0, 1.0F) ' Draw barcode label cardCanvas.DrawString(barcode.Value, font3, Brushes.Black, cardSize.Width / 2, 1.4F, stringFormat) ' Draw shoe size label cardCanvas.DrawString((shoeSizeStart + cardIndex * shoeSizeStep).ToString(), font4, Brushes.Black, _ cardSize.Width / 2, 1.7F, stringFormat) End Using ' Draw card on the page pageCanvas.DrawImage(cardBitmap, column * cardSize.Width, row * cardSize.Height) cardIndex = cardIndex + 1 Next Next End Using Return pageBitmap End Function End Class

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Barcode Suite Home Page

Explore ByteScout Barcode Suite Documentation

Explore Samples

Sign Up for ByteScout Barcode Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Barcode Suite Home Page

Explore ByteScout Barcode Suite Documentation

Explore Samples

Sign Up for ByteScout Barcode Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next