LaTeX Package to generate QR codes?

ctan now has the package qrcode, which doesn't need any tricks for pdfLaTeX. The default is a 2cm square, but an option allows you to change the height. (And since you specifically mentioned the width, I'll state the obvious fact that the height and width of the square are equal.) For example, the document

\documentclass{article}
\usepackage{qrcode}
\begin{document}

default:\quad
\qrcode{https://www.ctan.org/tex-archive/macros/latex/contrib/qrcode?lang=en}
\qquad
1 inch high (and wide):
\quad
\qrcode[height=1in]{https://www.ctan.org/tex-archive/macros/latex/contrib/qrcode?lang=en}

\end{document}

produces the output

qrcode examples


The pst-barcode package will work as follows:

\documentclass{standalone}
\usepackage{pst-barcode}
%\usepackage{auto-pst-pdf} % uncomment this if used with pdflatex
\begin{document}
  \begin{pspicture}(1in,1in)
    \psbarcode{test string}{}{qrcode}
  \end{pspicture}
\end{document}

The empty {} between the string to encode, {test string}, and the barcode type, {qrcode}, can contain options that are detailed in the package documentation (but which, by definition, are not needed).

The result wil the look like this:

enter image description here

NB: This package relies on pstricks, which of course uses postscript, so you can't use pdflatex to compile unless you uncomment the auto-pst-pdf package.


Not TeX-related, but since you inquired about a Python script...

#!/usr/bin/env python
# Generates QR code from given text using Google charts API.
import urllib2
import sys

# change those to your heart's content. See http://code.google.com/apis/chart/docs/gallery/qr_codes.html for more info
ENCODING='utf-8'
IMAGE_WIDTH=200
IMAGE_HEIGHT=200

def make_magic_url(text):
    # spaces in the text should be replaced with "+". probably other control symbols need to be handled in special way.
    return 'http://chart.apis.google.com/chart?chs=%dx%d&cht=qr&choe=%s&chl=%s' %(IMAGE_WIDTH, IMAGE_HEIGHT, ENCODING, text.replace(" ", "+"))

def makeQR(text, dest):
    print make_magic_url(text)
    myfig=urllib2.urlopen(make_magic_url(text))
    output=open(dest, 'wb')
    output.write(myfig.read())
    output.close()

text=sys.argv[1]
dest=sys.argv[2]
makeQR(text, dest)

Save this as fetchqr.py, or some such. Usage is simple:

python fetchqr.py 'http://tex.stackexchange.com/questions/1429/latex-package-to-generate-qr-codes' '/tmp/myfig.png'

And you'd get something like:

http://tex.stackexchange.com/questions/1429/latex-package-to-generate-qr-codes

This works on Python 2.6 under Windows, but I imagine it shouldn't be a a problem with older Python versions. Not sure about Python 3.x though.

If you're using something like a Makefile to run your project, then you should be able to generate those on the fly as needed -- maybe create a file with stuff to QR-code, then run all the entries through the grinder in one go.

The code is free for the taking.