barcode label size

  • Thread starter Thread starter ahmeddc
  • Start date Start date
A

ahmeddc

Guest
hi

The following code moves the strings from the datagrid to the print page and creates a barcode for each item. Everything is very good in the case of printing a4
The problem now is when you switch the printing machine with a barcode sticker machine
stc or zebra printer - in the following size label

25 mm * 38 mm or

convert to pixel = 93 * 138 pixel

The code shows the blank pages. I want to set the size of the print page with the barcode sticker machine .

Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
restValues()
barcodes.Clear()
For i As Integer = 0 To 100
Dim barcodeName As String = "barcod - " + i.ToString
Dim obj As Object() = {GenCode128.Code128Rendering.MakeBarcodeImage(barcodeName, 2, False), barcodeName}
barcodes.Add(obj)
'obj(0) = Image
Next
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
restValues()
PrintPreviewDialog1 = New PrintPreviewDialog
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.Show()
End Sub
Private barcodes As New List(Of Object())
Private index As Integer = 0
Private counter As Integer = 0
Private Distance As Integer = 25
Private Sub restValues()
index = 0
counter = 0
Distance = 25
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

For i As Integer = index To barcodes.Count - 1

Dim imagbarcode As Image = DirectCast(barcodes(i)(0), Image)
Dim barcodeName As String = DirectCast(barcodes(i)(1), String)
Dim font As Font = New Font("Arial", 12, FontStyle.Bold)
Dim stringSize As New SizeF(e.Graphics.MeasureString(barcodeName, font))

Dim imagWidth As Integer = imagbarcode.Width
Dim imagHeight As Integer = imagbarcode.Height
Dim pageHeight As Integer = counter + imagHeight + stringSize.Height + Distance

Dim pageX As Integer = CInt(e.PageBounds.Width / 2) - CInt(imagWidth / 2)

If pageHeight >= e.MarginBounds.Height Then

counter = 0
index = i
e.HasMorePages = True
Exit For

Else

e.HasMorePages = False
counter += imagHeight + stringSize.Height + Distance
e.Graphics.DrawString(barcodeName, font, New SolidBrush(Color.Black), pageX + CInt(imagWidth / 2) - CInt(stringSize.Width / 2), counter - stringSize.Height)
e.Graphics.DrawImage(imagbarcode, pageX, counter, imagWidth, imagHeight)

Dim cut = New Pen(Drawing.Color.Black, 1)
cut.DashStyle = Drawing.Drawing2D.DashStyle.Dash
e.Graphics.DrawRectangle(cut, pageX - 10, counter - 10 - stringSize.Height, imagWidth + 20, imagHeight + 20 + stringSize.Height)

End If

index = i

Next

End Sub

Continue reading...
 
Back
Top