# Is there a good LaTeX package for generating barcodes?

I'm looking for a good LaTeX package to generate one dimensional barcodes, that has the following properties.

1. It doesn't require any external scripts or internet connection to work.
2. It easily compiles to pdfs (so no pstricks hackery).

Do any such packages exist? An optional bonus would be if it could generate QR codes.

-
Does this answer your question? – Antal S-Z Dec 11 '10 at 4:06
I thought (but I have not tested) that pstricks works easily with pdftex now. No "hackery" is needed. – Aditya Dec 11 '10 at 4:20
@Antal S-Z: I had a look at that question but it seems (though I don't know this) that the USPS is some special case. I certainly couldn't find a nice easy command like \barcode{9412472141} that would just generate the appropriate barcode at the right spot with my quick scan of the documentation of the envlab answer. Actually now that I look at the other answer, it seems as though the makebarcode library does as I wish. I will mark this as the correct answer if someone wants to provide it. – bryn Dec 11 '10 at 5:39
Looks like a dupe of tex.stackexchange.com/questions/1429/… to me – Joseph Wright Dec 11 '10 at 7:55
@Joseph 2-dimensional QR codes and 1-dimensional barcodes are different things. – Caramdir Dec 11 '10 at 19:16
show 1 more comment

I wanted to try and tackle this question because I saw many solutions based on a dedicated font, and I thought: “Why use a font when you have perfectly good \vrule’s with TeX”. And so (in plain-tex):

% EAN-13 barcodes (also UPC if the first digit is zero)
\def\barcode#1#2#3#4#5#6#7{\begingroup% group the definitions inside
\dimen0=0.1em% width of a single rule (1em/7 ~ 0.1428571em; digit width = 0.5em)
\def\stack##1##2{\oalign{##1\cr\hidewidth##2\hidewidth}}
\def\bcskip##1{\kern##1\dimen0}
\def\bcrule##1{\vrule height10ex width##1\dimen0}
\def\bcL##1{\ifcase##1\bc3211##1\or\bc2221##1\or\bc2122##1\or\bc1411##1%
\or\bc1132##1\or\bc1231##1\or\bc1114##1\or\bc1312##1\or\bc1213##1\or\bc3112##1\fi}
\def\bc##1##2##3##4##5{\stack{\bcskip##1\bcrule##2\bcskip##3\bcrule##4}##5}
\def\bctmp{}
\def\bcR##1{\bgroup\let\bctmp\bcrule\let\bcrule\bcskip\let\bcskip\bctmp% invert L
\bcL##1\egroup}
\def\bcg##1##2##3##4##5{\stack{\bcskip##4\bcrule##3\bcskip##2\bcrule##1}##5}
\def\bcG##1{\bgroup\let\bc\bcg\bcL##1\egroup}% reverse
\stack{\bcskip9}#1% quiet zone
\bcrule1\bcskip1\bcrule1% start guard
\bcL#2% the second digit is always from L
\ifcase#1\bcL#3\bcL#4\bcL#5\bcL#6\bcL#7\or\bcL#3\bcG#4\bcL#5\bcG#6\bcG#7%
\or\bcL#3\bcG#4\bcG#5\bcL#6\bcG#7\or\bcL#3\bcG#4\bcG#5\bcG#6\bcL#7%
\or\bcG#3\bcL#4\bcL#5\bcG#6\bcG#7\or\bcG#3\bcG#4\bcL#5\bcL#6\bcG#7%
\or\bcG#3\bcG#4\bcG#5\bcL#6\bcL#7\or\bcG#3\bcL#4\bcG#5\bcL#6\bcG#7%
\or\bcG#3\bcL#4\bcG#5\bcG#6\bcL#7\or\bcG#3\bcG#4\bcL#5\bcG#6\bcL#7%
\fi%
\bcskip1\bcrule1\bcskip1\bcrule1\bcskip1% middle guard
\barcodeR}
\def\barcodeR#1#2#3#4#5#6{\bcR#1\bcR#2\bcR#3\bcR#4\bcR#5\bcR#6%
\bcrule1\bcskip1\bcrule1% end guard
\bcskip9% quiet zone
\endgroup}
%
\barcode 7046260816138


Which looks like:

-
This would be useful as a LaTeX package. – You Sep 19 '11 at 23:12
This is great! A CTAN package for this would be perfect. – ℝaphink Sep 20 '11 at 6:49
@ℝaphink: I think there already is: makebarcode – Tom Bombadil Oct 1 '12 at 12:09

With the pst-barcode-package you can produce all sorts of barcodes. For example,

\documentclass{minimal}
\usepackage{pst-barcode}

\begin{document}
\begin{pspicture}(3.5,1.2in)
\end{pspicture}
\end{document}


The disadvantage is of course that you have to go the latexdvipsps2pdf route for compilation, so it doesn't fulfill your requirement (2).

[I have never used pst-barcode myself, but I just saw this answer by Michael Underwood and thought that it applies here as well and might be useful for someone.]

-
This looks nice, but I'd really like something that transparently works with pdflatex. – bryn Dec 13 '10 at 5:37
it is no problem to run xelatex or pdflatex -shell-escape when you have \usepackage{auto-pst-pdf} – Herbert Jan 20 '11 at 19:15

Have a look at Typesetting Barcode in the TeX Catalogue Online. It lists some packages.

-