Dot Matrix Label Printing in vb.net
Dear all,
I've to develop a label printing application, for printing labels to two different dot matrix printers okidata and epson LQ300.
In this application, I need to print 3 labels, one for item description, one for list of items ordered and one for total amount for the ordered items, the label size is 2000/510 mm.
The no. of labels need to be printed will vary, when they order more items.
This is a web application and the codebehind is vb.net.I've created a class and instantiate the print object and pass the string and the printer name to the print object method.
Now my issue is it's printing to the actual label size but, the last line of the string is not printed though I've enough space left in the label to print it.
And is there a way to align the printer to some default setting.
The reason is, this webapplication is accessed by people at four different locations and this is application is temporarily deployed in my pc and I've added all the network printers to my pc and hence I capture their location and pass the printer name.. like
if strlocation = "aaa" then
printername = "\\jkp\epson_LQ300"
end if and so on..
Is there a better way to do all this and get the labels printed out wihtout any hassles.
Thanks in advance..
Re: Dot Matrix Label Printing in vb.net
Imports System.Data
Imports System.Data.OleDb
Imports System.Drawing.Printing
Partial Class _Default
Inherits System.Web.UI.Page
Dim myConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Databases\label.mdb")
Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim stritem, strDose, strFreq, strDuration, strInstruction, strTablets
Dim dblItem, dblPrice As Double
Dim decCustAmount As Decimal
stritem = ddlitem.SelectedItem.Text
strDose = ddlDose.SelectedItem.Text
strFreq = ddlFrequency.SelectedItem.Text
strDuration = ddlDuration.SelectedItem.Text
strInstruction = ddlInstruction.SelectedItem.Text
strTablets = txtTotal.Text
dblPrice = Val(txtTotalPrice.Text)
dblItem = Val(lblTotalItem.Text)
If ((strDose <> "") And (strFreq <> "")) Then
If (dblItem = 0) Then
lblitem1.Text = strItem
lblDose1.Text = strDose
lblFreq1.Text = strFreq
lblDuration1.Text = strDuration
lblInstruct1.Text = strInstruction
lblTablets1.Text = strTablets
lblPrice1.Text = dblPrice
lblTotalItem.Text = 1
lblAmount.Text = dblPrice
decCustAmount = Val(lblAmount.Text) + (Val(lblAmount.Text) * 0.05)
lblGST.Text = String.Format("{0:C}", decCustAmount)
ElseIf (dblItem = 1) Then
lblItem2.Text = strItem
lblDose2.Text = strDose
lblFreq2.Text = strFreq
lblDuration2.Text = strDuration
lblInstruct2.Text = strInstruction
lblTablets2.Text = strTablets
lblPrice2.Text = dblPrice
lblTotalItem.Text = 2
lblAmount.Text = Val(lblAmount.Text) + dblPrice
decCustAmount = Val(lblAmount.Text) + (Val(lblAmount.Text) * 0.05)
lblGST.Text = String.Format("{0:C}", decCustAmount)
ElseIf (dblItem = 2) Then
lblItem3.Text = strItem
lblDose3.Text = strDose
lblFreq3.Text = strFreq
lblDuration3.Text = strDuration
lblInstruct3.Text = strInstruction
lblTablets3.Text = strTablets
lblPrice3.Text = dblPrice
lblTotalItem.Text = 3
lblAmount.Text = Val(lblAmount.Text) + dblPrice
decCustAmount = Val(lblAmount.Text) + (Val(lblAmount.Text) * 0.05)
lblGST.Text = String.Format("{0:C}", decCustAmount)
ElseIf (dblItem = 3) Then
lblItem4.Text = strItem
lblDose4.Text = strDose
lblFreq4.Text = strFreq
lblDuration4.Text = strDuration
lblInstruct4.Text = strInstruction
lblTablets4.Text = strTablets
lblPrice4.Text = dblPrice
lblTotalItem.Text = 4
lblAmount.Text = Val(lblAmount.Text) + dblPrice
decCustAmount = Val(lblAmount.Text) + (Val(lblAmount.Text) * 0.05)
lblGST.Text = String.Format("{0:C}", decCustAmount)
End If
End If
End Sub
Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
'get the total no of items
Dim intTotal, intItem As Integer
intItem = Val(lblTotalItem.Text)
hiddenItem.Text = intItem
' get the location
Dim strLocation, strPrint, strtest1, strtest2, strtest3, strtest4, strTest, strPrinter As String
strLocation = ddlClinic.SelectedValue.ToString()
strPrint = strLocation
strtest1 = "\\test1\test_oki"
strtest2 = "\\test2\test-EPS"
strtest3 = "\\test3\test3-EPS"
strtest4 = "\\test4\test4_OKI"
If (strLocation = "test1") Then
strLocation = strLocation & vbCrLf & "test1 address"
strPrinter = strtest1
ElseIf (strLocation = "test2") Then
strLocation = strLocation & vbCrLf & "test2 address"
strPrinter = strtest2
ElseIf (strLocation = "test3") Then
strLocation = strLocation & vbCrLf & "test3 address"
strPrinter = strtest3
ElseIf (strLocation = "test4") Then
strLocation = strLocation & vbCrLf & "test4 address"
strPrinter = strtest4
End If
Dim myPrintObject, myPrintObject1, myPrintObject2 As TextPrint
Dim drawString, drawItems, drawAmount As String
drawString = ""
intTotal = 1
While (intTotal <= intItem)
If (intTotal = 1) Then
' Create string to draw.
drawString = vbCrLf & lblitem1.Text & vbCrLf & vbCrLf & lblDose1.Text & " " & lblFreq1.Text & vbCrLf & lblInstruct1.Text & vbCrLf & "Total: " & lblTablets1.Text & vbCrLf & txtPatient.Text & " " & Date.Today & vbCrLf & " " & strLocation
ElseIf (intTotal = 2) Then
drawString = vbCrLf & lblitem2.Text & vbCrLf & vbCrLf & lblDose2.Text & " " & lblFreq2.Text & vbCrLf & lblInstruct2.Text & vbCrLf & "Total: " & lblTablets2.Text & vbCrLf & txtPatient.Text & " " & Date.Today & vbCrLf & " " & strLocation
ElseIf (intTotal = 3) Then
drawString = vbCrLf & lblitem3.Text & vbCrLf & vbCrLf & lblDose3.Text & " " & lblFreq3.Text & vbCrLf & lblInstruct3.Text & vbCrLf & "Total: " & lblTablets3.Text & vbCrLf & txtPatient.Text & " " & Date.Today & vbCrLf & " " & strLocation
End If
myPrintObject = New TextPrint(drawString)
'Initialize Printing
myPrintObject.PrinterSettings.PrinterName = strPrinter
With myPrintObject.DefaultPageSettings
.PaperSize = New System.Drawing.Printing.PaperSize(System.Drawing.Printing.PaperKind.Custom, 300, 200)
End With
myPrintObject.Print()
intTotal += 1
End While
drawAmount = txtPatient.Text & " " & Date.Today & vbCrLf & vbCrLf & txtNRIC.Text & vbCrLf & "Item: " & lblTotalItem.Text & vbCrLf & "Total Amount: $ " & lblAmount.Text & vbCrLf & "Total Amt Payable(5%GST): $" & lblGST.Text & vbCrLf & " " & strLocation
myPrintObject2 = New TextPrint(drawAmount)
'Initialize Printing
myPrintObject2.PrinterSettings.PrinterName = strPrinter
' Issue print command
With myPrintObject2.DefaultPageSettings
.PaperSize = New System.Drawing.Printing.PaperSize(System.Drawing.Printing.PaperKind.Custom, 300, 200)
End With
myPrintObject2.Print()
drawItems = txtPatient.Text & " " & Date.Today & vbCrLf & txtNRIC.Text & vbCrLf & "Item: Disp"
If (intTotal = 1) Then
drawItems = drawItems & vbCrLf & lblitem1.Text & " " & lblTablets1.Text & vbCrLf & " " & strLocation
ElseIf (intTotal = 2) Then
drawItems = drawItems & vbCrLf & lblitem1.Text & " " & lblTablets1.Text & vbCrLf & lblDrug2.Text & " " & lblTablets2.Text & vbCrLf & " " & strLocation
ElseIf (intTotal = 3) Then
drawItems = drawItems & vbCrLf & lblitem1.Text & " " & lblTablets1.Text & vbCrLf & lblDrug2.Text & " " & lblTablets2.Text & vbCrLf & lblDrug3.Text & " " & lblTablets3.Text & vbCrLf & " " & strLocation
End If
myPrintObject1 = New TextPrint(drawItems)
'Initialize Printing
myPrintObject1.PrinterSettings.PrinterName = strPrinter
With myPrintObject1.DefaultPageSettings
.PaperSize = New System.Drawing.Printing.PaperSize(System.Drawing.Printing.PaperKind.Custom, 300, 200)
End With
myPrintObject1.Print()
End Sub
End Class
Re: Dot Matrix Label Printing in vb.net
The above trhead is my code.. is there any solution which i can use to fix it...