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.


6 Answers 6


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

  • 3
    FWIW, this package works fine with lualatex as well.
    – Raphael
    Commented Jul 3, 2018 at 13:13
  • Anyone knows if there is such a module for ConTeXt? Commented Apr 25, 2021 at 20:23

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.

  • 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
    Commented Aug 10, 2010 at 14:39
  • 4
    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. Commented Aug 17, 2010 at 14:18
  • 3
    for pdflatex see How to use PSTricks in pdfLaTeX?
    – doncherry
    Commented Aug 25, 2011 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.

  • Now I saw that this question is 4 months old. Oh well. Better late than never, I guess.. Commented Dec 9, 2010 at 17:35
  • 1
    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
    Commented Dec 9, 2010 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.


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

You can then include the image using the graphicx package.


That works really nicely, well done CTAN

Helps to put some '\vspace' around it

% never g g y u

Full document example below, A4 article format with headers foots toc etc

\def\tightlist{} % for pandoc
% Make the revision and doc number macro's then they are defined in one place
\ifthenelse {\boolean{european}}
\newcommand{\rev}{ PA1 } 
\newcommand{\etcdoc}{ DOCNUMBER-DES }
%North American
\newcommand{\etcdoc}{ DOCNUMBER-DES }


\title{ Some QR codes  \\ \etcdoc revision \rev}
\author{A.N. Other}
\chead{\textbf{Central header design notes.}}
\lfoot{\textbf{\small left footer \etcdoc Revision: \rev}}

\ifthenelse {\boolean{european}}
    European abstract
%% North American
    North American abstract 


\rfoot{ \textbf{ Page $\;$ \thepage $\;$  of $\;$ \pageref{LastPage}} }
\lfoot{  \textbf{\etcdoc Revision: \rev} }


Blah blah blah blah blah blah blah blah blah blah blah blah blah blah 

\section{Software Overview}

% the best book on programming ever!

\subsection{Additional Software Tools}

In the `C' language~\cite{DBLP:books/ph/KernighanR88} this can be very efficiently achieved by using some shifts and adds thus:
     int address,v=var_number;
     address = (v << 1) + ((v >> 2) << 3);   .
To find the address of a 16-bit complement of a variable simply add 8.
% never g g y u

Last Page.
typeset in {\Huge \LaTeX} \today.

And here is a bib file

% $Id: mybib.bib,v 1.5 2008/12/18 17:05:23 robin Exp $

 author = {Aho, Alfred V. and Kernighan, Brian W. and Weinberger, Peter J.},
 title = {The AWK programming language},
 year = {1987},
 isbn = {0-201-07981-X},
 publisher = {Addison-Wesley Longman Publishing Co., Inc.},
 address = {Boston, MA, USA},

  author    = {Brian W. Kernighan and
               Dennis Ritchie},
  title     = {The C Programming Language, Second Edition},
  publisher = {Prentice-Hall},
  year      = {1988},
  isbn      = {0-13-110370-9},
  bibsource = {DBLP, http://dblp.uni-trier.de}

      AUTHOR =       "A.~Balfour D.H.~Marwick",
        TITLE =        "Programming in Standard Fortran 77 ISBN 0-435-77486-7",
          PUBLISHER =    "Heinemann Educational Books",
            YEAR =         "1979"

 title = {The Art of Electronics},
 publisher = {Cambridge},
 year = {1989},
 author = {Paul Horowitz, Winfield Hill},
 OPTkey = {},
 OPTvolume = {},
 OPTnumber = {},
 OPTseries = {},
 OPTaddress = {},
 OPTedition = {2nd},
 OPTmonth = {},
 OPTnote = {},
 OPTannote = {},
 OPTurl = {},
 OPTdoi = {},
 OPTissn = {ISBN 0-521-37095-7},
 OPTlocalfile = {},
 OPTabstracts = {},
  • 1
    Welcome to TeX.SX! Could you please add a full working answer, for testing reasons?
    – Bobyandbob
    Commented Oct 2, 2018 at 9:12
  • 1
    What is the difference to Teepeemm 's answer?
    – Bobyandbob
    Commented Oct 2, 2018 at 9:38
  • Not alot, just nice spacing around it. Plus I have archived my template here so I can fetch it from other places on the internet. Also, have you followed the QR code on a phone say!
    – Robin
    Commented Oct 2, 2018 at 9:58
  • 1
    You are welcome. - Your example is a little bit over loaded. If you like to add a example with bibliography-i don't know why it should be necessary here- be care of (MWEB), so everyone should compile it, without modifications.
    – Bobyandbob
    Commented Oct 2, 2018 at 11:22
  • I can add a mybib.bib (cut down of course) ... should I?
    – Robin
    Commented Oct 2, 2018 at 11:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .