qr code printing

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 639 Views - Last Post: 06 March 2019 - 02:04 AM Rate Topic: -----

#1 ssagp   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 01-March 19

qr code printing

Posted 01 March 2019 - 02:32 AM

 BarcodeWriter writer = new BarcodeWriter
            {
              
                Format = BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions
                {
                    //ErrorCorrection = ErrorCorrectionLevel.L,
                  ////  PureBarcode = true,
                    Width = 100,
                    Height = 100,
                    Margin = 1
                   
               
                }
            };

:code:
I need to print qr code to a label.How can i adjust qr image positioning using c# .I have tried
             Margins margins = new Margins(10, 10, 10, 10);
             printDocument1.PrinterSettings.DefaultPageSettings.Margins = margins;
             printPreviewDialog1.Show();
:code:

This post has been edited by modi123_1: 01 March 2019 - 07:50 AM


Is This A Good Question/Topic? 0
  • +

Replies To: qr code printing

#2 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6763
  • View blog
  • Posts: 23,066
  • Joined: 05-May 12

Re: qr code printing

Posted 01 March 2019 - 08:40 AM

Since we don't even know how BarcodeWriter works, it may help if you provide us some background or a pointer to their documentation.
Was This Post Helpful? 1
  • +
  • -

#3 hexagod   User is online

  • 😂😂😂
  • member icon

Reputation: 24
  • View blog
  • Posts: 559
  • Joined: 29-October 16

Re: qr code printing

Posted 01 March 2019 - 09:47 AM

I would think he could do it post output from that API, regardless of the QrCodeEncodingOptions

When you change those margin integers, that doesn't adjust positioning? Can you show us your full code related to the .NET printing API?

I'm installing ZXing now I'll see if I can figure it out.
Was This Post Helpful? 1
  • +
  • -

#4 hexagod   User is online

  • 😂😂😂
  • member icon

Reputation: 24
  • View blog
  • Posts: 559
  • Joined: 29-October 16

Re: qr code printing

Posted 01 March 2019 - 10:07 AM

Looks like that Margin int only controls horizontal. And those Width and Height ints only work when divisible by some other number that I'm not aware of. Apparently you can't just use any int for them because of the way QRCode works.

I'd say if you're just looking to adjust where the barcode prints it'll be easier to do that through .NET since I don't see any vertical margin parameter in ZXing.

Attached image(s)

  • Attached Image

Was This Post Helpful? 1
  • +
  • -

#5 hexagod   User is online

  • 😂😂😂
  • member icon

Reputation: 24
  • View blog
  • Posts: 559
  • Joined: 29-October 16

Re: qr code printing

Posted 01 March 2019 - 11:07 AM

Margins(left, right, top, bottom)


... This adjusts the entire page margin though. There must be some other number controlling inter-page positioning within the report. I'm at the end of how far I can help with this until I get more snips and details on your project.

Attached image(s)

  • Attached Image

This post has been edited by hexagod: 01 March 2019 - 11:09 AM

Was This Post Helpful? 1
  • +
  • -

#6 ssagp   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 01-March 19

Re: qr code printing

Posted 01 March 2019 - 08:28 PM

            BarcodeWriter writer = new BarcodeWriter
            {
              
                Format = BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions
                {
                    //ErrorCorrection = ErrorCorrectionLevel.L,
                  ////  PureBarcode = true,
                    Width = 100,
                    Height = 100,
                    Margin = 10,
                   
               
                }
            };
            
            var result = writer.Write(txt);
            var barcodeBitmap = new Bitmap(result);
            pictureBox1.Image = barcodeBitmap;
          

            barcodeBitmap.Save(Application.StartupPath + @"\Code_" + DateTime.Now.ToString("d_MM_yy_HH_mm_ss") + ".png");
        }



        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            
            Bitmap bm = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            pictureBox1.DrawToBitmap(bm, new Rectangle(0,0,pictureBox1.Width,pictureBox1.Height));
            e.Graphics.DrawImage(bm,0,0);

       
          
        }

        private void button2_Click(object sender, EventArgs e)
        {
             PrintDialog pd = new PrintDialog();
            PrintDocument doc = new PrintDocument();
            doc.PrintPage += printDocument1_PrintPage;
            pd.Document = doc;
            printDocument1.PrinterSettings.PrinterName = "Honeywell PC42t (203 dpi) - DP (Copy 1)";
            Margins margins = new Margins(10, 10, 10, 10);
            printDocument1.PrinterSettings.DefaultPageSettings.Margins = margins;
            PrinterSettings ps = new PrinterSettings();
            if(pd.ShowDialog() == DialogResult.OK)
            {
                doc.Print(); 
            }
        }


This post has been edited by Skydiver: 01 March 2019 - 09:02 PM
Reason for edit:: Put code in code tags. Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#7 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6763
  • View blog
  • Posts: 23,066
  • Joined: 05-May 12

Re: qr code printing

Posted 01 March 2019 - 09:37 PM

Read the documentation. Look at your line 32. What do you think the last two parameters are for?
Was This Post Helpful? 1
  • +
  • -

#8 ssagp   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 01-March 19

Re: qr code printing

Posted 01 March 2019 - 10:33 PM

Ya Its for the bitmap position.I have tried changing the coordinates.

This post has been edited by Skydiver: 02 March 2019 - 06:42 AM
Reason for edit:: Removed unnecessary quote. There is no need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#9 ssagp   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 01-March 19

Re: qr code printing

Posted 01 March 2019 - 10:42 PM

View Posthexagod, on 01 March 2019 - 11:07 AM, said:

I'm at the end of how far I can help with this until I get more snips and details on your project.


Its for generating qr code for a file and to print it on a label from honeywell pc 42 t printer

This post has been edited by Skydiver: 02 March 2019 - 06:43 AM
Reason for edit:: Trimmed quote down. Keep quotes focused.

Was This Post Helpful? 0
  • +
  • -

#10 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6763
  • View blog
  • Posts: 23,066
  • Joined: 05-May 12

Re: qr code printing

Posted 02 March 2019 - 06:40 AM

Yes, you tried changing the coordinates, and what was the results you were getting? Recall that the resolution of a printer is different than that of the screen.

Also, there is no need to quote the post above yours. Just use the big Reply button or the Fast Reply area.
Was This Post Helpful? 0
  • +
  • -

#11 hexagod   User is online

  • 😂😂😂
  • member icon

Reputation: 24
  • View blog
  • Posts: 559
  • Joined: 29-October 16

Re: qr code printing

Posted 03 March 2019 - 09:54 AM

ssagp Sorry for the no response; I usually spend Friday/Saturday making music. The way I see it, you have a few options here:

pictureBox1.DrawToBitmap(bm, new Rectangle(0,0,pictureBox1.Width,pictureBox1.Height));

Those picturebox width and height parameters could be changed, but I wouldn't. The device that will be reading the QRCode is programmed to read based upon very fine parameters in terms of ratio of the rectangles inside your image. If you adjust this too much, the QRCode might be unreadable.

The width and height parameters shouldn't be changed IMO, but it looks like we may be able to change some of the other parameters within our Rectangle class:

https://docs.microso...framework-4.7.2

Quote

The following example draws a rectangle with its upper-left corner at (10, 10). The rectangle has a width of 100 and a height of 50.


Rectangle(10, 10, 100, 50);


So the 10,10 could potentially be used in your case to move the position of your QRCode rectangle in respect to the upper left corner. As the ints get larger, you're getting farther away from the upper left hand corner. Use them to adjust the positioning of your rectangle. Try increasing those ints gradually and see if you can get the QRCode within the bitmap to be where you want it to be.

As Skydiver pointed out, another option that you have is to change the draw position coordinates within DrawImage

https://docs.microso...framework-4.7.2

Quote

public void DrawImage (System.Drawing.Image image, float x, float y, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit);

Parameters

image
Image

Image to draw.

x
Single

The x-coordinate of the upper-left corner of the drawn image.

y
Single

The y-coordinate of the upper-left corner of the drawn image.


Ignore the srcUnit param; I believe it is optional. The x and y parameters within DrawImage could also be used to adjust where your image is drawn (post bitmap creation).

Try something like:

e.Graphics.DrawImage(bm,50,50);

OR

e.Graphics.DrawImage(bm,-50,-50);

and see what that does for you.

The only other thing that I can see you have the option of changing is:

Margins margins = new Margins(10, 10, 10, 10);

but again, it changes the margins of the entire page. So I'm not sure that's the best way to do this.

Beyond that, I would need to see a picture of what's wrong with your printout and then I can assist you further.

I hope this helps, good luck and LMK

This post has been edited by hexagod: 03 March 2019 - 09:58 AM

Was This Post Helpful? 1
  • +
  • -

#12 ssagp   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 01-March 19

Re: qr code printing

Posted 04 March 2019 - 12:11 AM

is there any difference for normal image file conversion and a binary file conversion to qr code
Was This Post Helpful? 0
  • +
  • -

#13 ssagp   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 01-March 19

Re: qr code printing

Posted 04 March 2019 - 12:17 AM

I have a binary file and I have to convert the file into qr code.I used the normal file upload option to create qr code using ZXing library.While reading the qr code it is having error.

OpenFileDialog op1 = new OpenFileDialog();
            op1.Multiselect = false;
            op1.InitialDirectory = Application.StartupPath;
            op1.ShowDialog();
            op1.Filter = "allfiles|*.bin";

            Encoding m_encoding = Encoding.GetEncoding("ISO-8859-1");
            byte[] dataFromFile = System.IO.File.ReadAllBytes(op1.FileName);
            string txt = m_encoding.GetString(dataFromFile);
            int tt = txt.Length;
            

            BarcodeWriter writer = new BarcodeWriter
            {
              
                Format = BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions
                {
                    ErrorCorrection = ErrorCorrectionLevel.L,
                    Height = 145,
                    Width = 145,
                }
            };

            var result = writer.Write(txt);
            var barcodeBitmap = new Bitmap(result);
            pictureBox1.Image = barcodeBitmap;

This post has been edited by andrewsw: 04 March 2019 - 02:08 AM
Reason for edit:: added missing [code][/code] tags

Was This Post Helpful? 0
  • +
  • -

#14 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6736
  • View blog
  • Posts: 27,734
  • Joined: 12-December 12

Re: qr code printing

Posted 04 March 2019 - 02:07 AM

Please do not open a new topic on the same subject. Topics merged. And wrap your code in code tags.
Was This Post Helpful? 0
  • +
  • -

#15 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6763
  • View blog
  • Posts: 23,066
  • Joined: 05-May 12

Re: qr code printing

Posted 04 March 2019 - 04:31 AM

what error are you getting?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2