45

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.

9
  • Does this answer your question? Commented Dec 11, 2010 at 4:06
  • I thought (but I have not tested) that pstricks works easily with pdftex now. No "hackery" is needed.
    – Aditya
    Commented Dec 11, 2010 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
    Commented Dec 11, 2010 at 5:39
  • Looks like a dupe of tex.stackexchange.com/questions/1429/… to me
    – Joseph Wright
    Commented Dec 11, 2010 at 7:55
  • 2
    @Joseph 2-dimensional QR codes and 1-dimensional barcodes are different things.
    – Caramdir
    Commented Dec 11, 2010 at 19:16

5 Answers 5

49

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):

\def\barcode#1#2#3#4#5#6#7{\begingroup%
  \dimen0=0.1em
  \def\stack##1##2{\oalign{##1\cr\hidewidth##2\hidewidth}}%
  \def\0##1{\kern##1\dimen0}%
  \def\1##1{\vrule height10ex width##1\dimen0}%
  \def\L##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\R##1{\bgroup\let\next\1\let\1\0\let\0\next\L##1\egroup}%
  \def\G##1{\bgroup\let\bc\bcg\L##1\egroup}% reverse
  \def\bc##1##2##3##4##5{\stack{\0##1\1##2\0##3\1##4}##5}%
  \def\bcg##1##2##3##4##5{\stack{\0##4\1##3\0##2\1##1}##5}%
  \def\bcR##1##2##3##4##5##6{\R##1\R##2\R##3\R##4\R##5\R##6\11\01\11\09%
    \endgroup}%
  \stack{\09}#1\11\01\11\L#2%
  \ifcase#1\L#3\L#4\L#5\L#6\L#7\or\L#3\G#4\L#5\G#6\G#7%
    \or\L#3\G#4\G#5\L#6\G#7\or\L#3\G#4\G#5\G#6\L#7%
    \or\G#3\L#4\L#5\G#6\G#7\or\G#3\G#4\L#5\L#6\G#7%
    \or\G#3\G#4\G#5\L#6\L#7\or\G#3\L#4\G#5\L#6\G#7%
    \or\G#3\L#4\G#5\G#6\L#7\or\G#3\G#4\L#5\G#6\L#7%
  \fi\01\11\01\11\01\bcR}

\barcode 7046260816138
\bye

Which looks like: ean13barcode

3
  • 7
    This would be useful as a LaTeX package.
    – You
    Commented Sep 19, 2011 at 23:12
  • 3
    This is great! A CTAN package for this would be perfect.
    – raphink
    Commented Sep 20, 2011 at 6:49
  • 3
    @ℝaphink: I think there already is: makebarcode Commented Oct 1, 2012 at 12:09
27

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)
    \psbarcode{12345678}{includetext inkspread=0.5}{ean8}
\end{pspicture}
\end{document}

example

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.]

3
  • This looks nice, but I'd really like something that transparently works with pdflatex.
    – bryn
    Commented Dec 13, 2010 at 5:37
  • 8
    it is no problem to run xelatex or pdflatex -shell-escape when you have \usepackage{auto-pst-pdf}
    – user2478
    Commented Jan 20, 2011 at 19:15
  • I've tried to run the above MWE plus the auto-pst-pdf package and the shell escpe flag. The tex document compiled without errors but not PDF has been generated.
    – Maxiride
    Commented Mar 22, 2020 at 19:32
13

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

5

You can take a look on barracuda package that directly generate PDF vector graphics with an internal Lua library. So, it works with any Lua-based typesetting engine like LuaLaTeX, filling inside an hbox the symbols. A minimal example with the barracuda.sty LaTeX package is showed here:

% !TeX program = LuaLaTeX
\documentclass{article}
\usepackage{barracuda}
\begin{document}
\barracuda{code39}{123ABC}
\end{document}
4

There is the ean13isbn package: http://www.ctan.org/pkg/ean13isbn. Then there is the GS1 package: http://www.ctan.org/pkg/gs1. Both can produce EAN8 and EAN13. But I am completely disappointed that both packages use bitmap fonts (not outline fonts) for the digits below the barcode. If, in case of the GS1 package, I turn off the usage of the ocrb font, the result looks bad. The numbers are too close to the barcode. The ean13isbn package doesn't have many options it seems. And I am not really sure how I set a different font. For both packages however, the barcode itself it not a bitmap which should be a good thing as far as print quality is concerned.

And then we have this online ISBN barcode generator: http://bookow.com/resources.php. This is the best one I have found so far in the sense that (1) it generates PDFs with vector graphics and (2) the PDF contains the text as outlines. There are no pixels whatsoever in the PDF. However, the text font is not embedded in the PDF. I'm pretty sure it can be abused for EAN13 codes in general, if one clips the ISBN text away.

1
  • My macro ean13.tex uses the font ocrb9 which is available in outline form, of course (ocrb9.otf, orcb9.pfb)
    – wipet
    Commented Nov 25, 2015 at 20:13

You must log in to answer this question.

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