Click here to Skip to main content
15,904,023 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello everybody
I am working on a project and it is almost ready but the last thing to do is to print a QR code on the receipt.

I am saving the details to be printed in a text file an later print the text file to a local printer which is just working fine. Now the customer is asking to print a QR code on the receipt which should include the name of the person, date and bill total which i am able to create with the following code.

To generate QR code i use the following code
VB
Imports ThoughtWorks.QRCode.Codec;

Dim objqrcode As QRCodeEncoder = New QRCodeEncoder
Dim imgimage As Image
Dim objbitmap As Bitmap
Dim s As String
s = "Sarfaraz M Bhat Age=10 and Class=30"
objqrcode.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE
objqrcode.QRCodeScale = 3
objqrcode.QRCodeVersion = 6
objqrcode.QRCodeErrorCorrect = ThoughtWorks.QRCode.Codec.QRCodeEncoder.ERROR_CORRECTION.L
imgimage = objqrcode.Encode(s)
objbitmap = New Bitmap(imgimage)
objbitmap.Save("QRCode.jpg")
Pimage.ImageLocation = "QRCode.jpg";

I am able to load the QR code in a picture box in vb.net but how to print this QR image at a proper place on the receipt.

What I have tried:

I am able to create a QR code and print it with the following code
VB
  Dim WithEvents PD As New Printing.PrintDocument
 PD.Print()

Private Sub PD_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PD.PrintPage
        'e.Graphics.DrawImage(Pimage.Image, e.MarginBounds.Left, e.MarginBounds.Top)
        e.Graphics.DrawImage(Pimage.Image, Pimage.Bounds)

    End Sub
Posted
Updated 4-Oct-16 22:59pm
v3
Comments
Richard MacCutchan 5-Oct-16 5:17am    
You need to design a full printing module that includes all the details requested by the customer. What exactly is the problem?
sarfarazbhat 6-Oct-16 1:05am    
I need to print a receipt where there are different details to be printed.
I am saving the details in a text file with the following code and Print the text file. Everything is going good but now i need to print an image (QR code) on the same paper where the text file is being printed.But when i try to print the image is being printed on a different page rather than on the page where the text file gets printed.
The code for text file is as under

Dim file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter("digimate.txt", False)

Dim x As Integer
Dim total As Integer
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.Write("{0,-9}", "Bill No:")
file.Write("{0,-25}", txtbillno.Text)
file.Write("{0,10}", "Dated :")
file.Write("{0,-22}", dtpick.Text.ToString)
file.WriteLine()
file.Write("{0,-9}", "Name :")
file.Write("{0,-25}", frmcustomer.lblname.Text)
file.Write("{0,10}", "Address:")
file.Write("{0,-22}", frmcustomer.lbladdress.Text)
file.WriteLine()
file.Write("{0,-9}", "Contact:")
file.Write("{0,-25}", frmcustomer.lblcontact.Text)
file.Write("{0,10}", "Email :")
file.WriteLine("{0,-22}", frmcustomer.lblemail.Text)
file.WriteLine("-----------------------------------------------------------------")
file.Write("{0,-7}", "S.NO")
file.Write("{0,-30}", "ITEMS ORDERED")
file.Write("{0,7}", "RATE")
file.Write("{0,7}", "LENGTH")
file.Write("{0,7}", "WIDTH")
file.WriteLine("{0,7}", "TOTAL")
file.WriteLine("-----------------------------------------------------------------") '66
For x = 0 To dgselecteditems.Rows.Count - 1
file.Write("{0,-7}", x + 1)
file.Write("{0,-30}", dgselecteditems.Rows(x).Cells("itemname").Value)
file.Write("{0,7}", dgselecteditems.Rows(x).Cells("rate").Value)
file.Write("{0,7}", dgselecteditems.Rows(x).Cells("length").Value)
file.Write("{0,7}", dgselecteditems.Rows(x).Cells("width").Value)
file.Write("{0,7}", dgselecteditems.Rows(x).Cells("amount").Value)
total += dgselecteditems.Rows(x).Cells("amount").Value
file.WriteLine()
Next
file.WriteLine("-----------------------------------------------------------------")
file.Write("{0,-7}", "")
file.Write("{0,-30}", "Total Amount =")
file.WriteLine("{0,28}", total)
file.WriteLine("-----------------------------------------------------------------")
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.Write("{0,58}", "Sales Tax @ 13.5% due :")
file.WriteLine("{0,7}", txttaxdue.Text)
file.Write("{0,58}", "Sales Tax @ 13.5% charged:")
file.WriteLine("{0,7}", txttaxcharged.Text)
'file.WriteLine("------------------------------------------------------------------")
file.WriteLine()
file.Write("{0,-9}", "Total due:")
tc = total + Val(txttaxcharged.Text)
' qrtotal = tc
Dim temp As String = RupeesToWord(tc)
file.Write("{0,45}", temp)
file.Close()

Do i have to save the pic in a text file which i know can not be saved then how to print the image.
Thank you
Richard MacCutchan 6-Oct-16 5:10am    
Well I am afraid you are doing it the wrong way. You need to add proper print handling to your code to generate the output onto a single sheet of paper. See https://www.google.com/search?q=vb.net+print[^] for samples and tutorials on printing in .NET.
sarfarazbhat 6-Oct-16 1:07am    
I need to print a receipt where there are different details to be printed.
I am saving the details in a text file with the following code and Print the text file. Everything is going good but now i need to print an image (QR code) on the same paper where the text file is being printed.But when i try to print the image is being printed on a different page rather than on the page where the text file gets printed.
The code for text file is as under

Dim file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter("digimate.txt", False)

Dim x As Integer
Dim total As Integer
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.Write("{0,-9}", "Bill No:")
file.Write("{0,-25}", txtbillno.Text)
file.Write("{0,10}", "Dated :")
file.Write("{0,-22}", dtpick.Text.ToString)
file.WriteLine()
file.Write("{0,-9}", "Name :")
file.Write("{0,-25}", frmcustomer.lblname.Text)
file.Write("{0,10}", "Address:")
file.Write("{0,-22}", frmcustomer.lbladdress.Text)
file.WriteLine()
file.Write("{0,-9}", "Contact:")
file.Write("{0,-25}", frmcustomer.lblcontact.Text)
file.Write("{0,10}", "Email :")
file.WriteLine("{0,-22}", frmcustomer.lblemail.Text)
file.WriteLine("-----------------------------------------------------------------")
file.Write("{0,-7}", "S.NO")
file.Write("{0,-30}", "ITEMS ORDERED")
file.Write("{0,7}", "RATE")
file.Write("{0,7}", "LENGTH")
file.Write("{0,7}", "WIDTH")
file.WriteLine("{0,7}", "TOTAL")
file.WriteLine("-----------------------------------------------------------------") '66
For x = 0 To dgselecteditems.Rows.Count - 1
file.Write("{0,-7}", x + 1)
file.Write("{0,-30}", dgselecteditems.Rows(x).Cells("itemname").Value)
file.Write("{0,7}", dgselecteditems.Rows(x).Cells("rate").Value)
file.Write("{0,7}", dgselecteditems.Rows(x).Cells("length").Value)
file.Write("{0,7}", dgselecteditems.Rows(x).Cells("width").Value)
file.Write("{0,7}", dgselecteditems.Rows(x).Cells("amount").Value)
total += dgselecteditems.Rows(x).Cells("amount").Value
file.WriteLine()
Next
file.WriteLine("-----------------------------------------------------------------")
file.Write("{0,-7}", "")
file.Write("{0,-30}", "Total Amount =")
file.WriteLine("{0,28}", total)
file.WriteLine("-----------------------------------------------------------------")
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.WriteLine()
file.Write("{0,58}", "Sales Tax @ 13.5% due :")
file.WriteLine("{0,7}", txttaxdue.Text)
file.Write("{0,58}", "Sales Tax @ 13.5% charged:")
file.WriteLine("{0,7}", txttaxcharged.Text)
'file.WriteLine("------------------------------------------------------------------")
file.WriteLine()
file.Write("{0,-9}", "Total due:")
tc = total + Val(txttaxcharged.Text)
' qrtotal = tc
Dim temp As String = RupeesToWord(tc)
file.Write("{0,45}", temp)
file.Close()

Do i have to save the pic in a text file which i know can not be saved then how to print the image.
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900