Results 1 to 2 of 2

Thread: [RESOLVED] Barcode (QR) position detection

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2018

    Resolved [RESOLVED] Barcode (QR) position detection


    I need a way of getting the co-ordinates of a QR code on a pdf.

    Here's a bit of background to this:

    I have a bunch of pdfs with QR codes in various positions (they are positioned by another user, outside of my control).

    I'm currently working out the area the QR manually, then using Ghostscript to convert the pdf to a png file showing just the QR code (ie I'm cropping to the graphic)

    Once I've done this I'm using the library to decode the QR from the png file. I've found ZXing (and other libraries I've found) work best if I give them a graphic with just the QR on to look at, hence the crop.

    This works fine, but I've now given the task of coming up with some way of batch processing a bunch of pdfs with placeholder QR codes (ie a bit of standard text, the same every time), and replacing this QR with a new one based on variable data.

    Once I have the co-ords I can relate that back to the pdf, create the new barcode as a graphic, and finally use itextsharp to stamp it over the top of the placeholder one.

    So the problem is getting the co-ordinates.

    I've seen several libraries, such as, which can decode a QR but I haven't found anything that will tell me the co-ords.

    My only idea is to come up with some code which reads the png file pixel by pixel and look for a pattern of black and white squares, and thus try to find the QR code that way.

    This seems VERY long-winded and may be open to problems - eg it might be tricky to distinguish a QR code from simple black text on a white background. I wondered if a better way is know by anyone?

    Thanks for reading - sorry it was a bit lengthy!

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Sep 2018

    Re: Barcode (QR) position detection

    I've just found can give you the co-ordinates of the middle of the 'positioning' or locator squares within the QR code.

    Once you have those, with a bit of vb you can scan back a few pixels on the x and y axis and test the colours to see when they change, and thereby find the actual edges of the QR graphic (which I needed). From there you can work out the height/width.

    Here's the link which shows how you get the co-ords from ZXing. Hope this helps someone.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width