Create a project name as QRCode Generator
Add the MessagingToolkit from manage nuget package option, just right click on QRcode generator project

Design for Window form

Click on open txt File button to select the file as well as read the string from the file.

Double click on open txt file Button and code as shown below
- private void button1_Click(object sender, EventArgs e)
- {
- OpenFileDialog openFileDialog1 = new OpenFileDialog();
- if (openFileDialog1.ShowDialog() == DialogResult.OK)
- {
- string filename = openFileDialog1.FileName;
- txtPath.Text = filename;
- string str = File.ReadAllText(filename);
- string str1 = str.Substring(2368);
- string STR2 = str1.Remove(953);
- textencode.Text = STR2;
- }
- }

Press F4 on invoice textbox and search the keypress event and double click on it.
- private void text_Invoice_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.Handled = !Char.IsDigit(e.KeyChar))
- {
- MessageBox.Show("Allow only 10 digit numeric values ");
- }
- }
Click on QrCode Generate button.
- private void btn_encoder_Click(object sender, EventArgs e)
- {
- string path = @"d:\\QRCode\\" + text_Invoice.Text+".bmp";
- MessagingToolkit.QRCode.Codec.QRCodeEncoder encoder = new MessagingToolkit.QRCode.Codec.QRCodeEncoder();
- encoder.QRCodeScale = 8;
- Bitmap bmp = new Bitmap(encoder.Encode(textencode.Text),new Size(200,200));
- pictureBox.Image = bmp;
- var newBmp = bmp.Clone(new Rectangle(0, 0, bmp.Width, bmp.Height), PixelFormat.Format8bppIndexed);
- folderBrowserDialog1.SelectedPath = path;
- if (text_Invoice.Text.Trim() == string.Empty)
- {
- MessageBox.Show("Please enter Invoce number before generate the QRCode");
- return;
- }
- else if (textencode.Text.Trim() == string.Empty)
- {
- MessageBox.Show("Please select the text file ");
- return;
- }
- else
- {
- newBmp.Save(path, ImageFormat.Bmp);
- MessageBox.Show("QRCode "+ text_Invoice.Text+ ".bmp save sucessfully");
- textencode.Text = "";
- text_Invoice.Text = "";
- }
- }

Save image in D:/Qrcode as a given name in invoice textbox


Shyam YadavPosted Jul 11, 2023, 10:47 AM
Dear Amar Singh Manoor , after generation the qr Code from JSON it shows the Message "unable to Verify QR Code as it does not contain the valid e-Invoice signed content". while from GST login E-Invoice it scan properly. Please help me
ahmed selimPosted Dec 16, 2021, 7:40 AM
Could you please mr . Amar post a sample how extract signed invoice .thanks
ahmed selimPosted Dec 16, 2021, 7:33 AM
How to got json file
SARFARAJ SHAIKHPosted Apr 24, 2021, 6:01 AM
How to got json file
WDMS SMGROUPPosted Apr 3, 2021, 6:05 AM
Error coming startIndex cannot be larger than length of string. I am passing singed qr code
VAGEESH TAVARADPosted Apr 1, 2021, 2:46 AM
Sir for me the QR code generated using this code is not getting scanned..where i am doing wrong
kk bcicPosted Jan 20, 2021, 5:54 AM
What does that json.txt file contains?
John CyriacPosted Dec 5, 2020, 4:01 AM
Well done Amar , could you post a sample how extract signed invoice also
vijay karnatakPosted May 30, 2020, 3:39 AM
Good job Mr. Amar Singh