TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to be able to generate QR barcodes in my LaTeX documents, and I'm having a hard time finding a solution. The use would be a command such as

\qr[1in]{Your text to be QR encoded here}

The optional argument would be the width of the square. I'd be using this to put a barcode on each page of an exam for my students, so that the assignments could be scanned and sorted electronically once they hand them in.

Anyone know of such a package? I don't mind using an external script (e.g., python) to generate a graphic that I could include.

share|improve this question
I love the idea, but what machine is going to do the sorting? – Matthew Leingang Feb 8 '11 at 13:07
There is a scanner in my office that can scan to PDF. At that point I can do everything in software. – MattoxBeckman Feb 14 '12 at 18:27
A LuaTeX solution can be found in tex.stackexchange.com/a/88610/243 – topskip Apr 14 '13 at 19:40
Possible duplicate of pgf-Tikz QR code generator – Teepeemm Jun 20 at 3:55
up vote 38 down vote accepted

The pst-barcode package will work as follows:

%\usepackage{auto-pst-pdf} % uncomment this if used with pdflatex
    \psbarcode{test string}{}{qrcode}

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.

share|improve this answer
This seems to be a wrapper package for the Barcode Writer in Pure Postscript. I've been looking for a way of doing the same thing (QRcode) compatible with pdftex/pdflatex for quite some time. I even have a rather dirty series of macros that accomplishes the rendering end of it, writing a code generator for it is the tough part though. – Giel Aug 10 '10 at 14:39
I was hoping for something compatible with tikz/pdflatex as well; perhaps it would not be too hard to write a wrapper for it, and throw in a ps2pdf command. If I ever do such a thing I'll post back here. – MattoxBeckman Aug 17 '10 at 14:18
for pdflatex see How to use PSTricks in pdfLaTeX? – doncherry Aug 25 '11 at 23:42

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

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)
    output=open(dest, 'wb')

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:


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.

share|improve this answer
Now I saw that this question is 4 months old. Oh well. Better late than never, I guess.. – Martin Tapankov Dec 9 '10 at 17:35
It would be nice if a vector image is outputted instead of png, although, scaling it will not affect it worse off course. – Peter Smit Dec 9 '10 at 18:38

I made such a package in plainTeX ... it has a bit different interface. Your interface would have for example problems to include braces in the QRcode. The source code is not easy to understand as the math behind it is rather complicated, but I hope the initial comments explain usage well enough. See http://ktiml.mff.cuni.cz/~maj/QRcode.TeX. There could be changes in the file in the future, but current version seems to work well.

share|improve this answer
BTW: I don't expect problems with using this package inside LeTeX, but of course nothing is guaranted. – Vladan Majerech Apr 14 '13 at 19:20
Welcome to TeX.sx! – Peter Jansson Apr 14 '13 at 19:34

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


1 inch high (and wide):


produces the output

qrcode examples

share|improve this answer

This isn't really what you're looking for, but an easy way to generate QR codes is with Google's chart tool: http://code.google.com/intl/en/apis/chart/infographics/docs/qr_codes.html

You can then include the image using the graphicx package.

share|improve this answer

http://www.tug.org/pipermail/texhax/2009-September/013160.html should be a help for using pstricks in general

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.