24

Is there any package that generates 2d barcodes (QR code). I want to add a barcode on the front page of a manual I have written containing the URL where to download that manual. It would be nice if I could continue using pdflatex. Instead of converting each time.

EDIT: [Reaction to Jake's answer]

Is it possible one could only add one barcode. I've analyzed how this works. I think the compiler runs two times, one time rendering the pstricks images. A second time inserting the images in the LaTeX pdf. However if I add two different barcodes. It simply overides the file by the last barcode, and uses this file for both the barcodes. Is there any workaround for this problem?

  • This question might be of some help. The answers seem to use pstricks though. – TH. Feb 08 '11 at 11:37
  • 1
    Indeed, but there it only compiles to .ps files. Of course one could write a simple bash script always converting the .ps file to a .pdf, but I was looking for a more elegant solution. – willeM_ Van Onsem Feb 08 '11 at 11:48
  • 1
    If you include the package auto-pst-pdf, you don't need to go through the conversion step. See my answer. – Jake Feb 08 '11 at 11:52
  • 1
    run it with xetex and you do not need the auto-pst-pdf package –  Feb 08 '11 at 12:39

3 Answers3

14

This will work directly with pdflatex:

\documentclass{article}
\usepackage{pst-barcode}
\usepackage{auto-pst-pdf}
\begin{document}
  \begin{pspicture}(0.7in,0.7in)
    \psbarcode{http://www.ctan.org}{}{qrcode}
  \end{pspicture}
\end{document}
Jake
  • 232,450
  • Using this solution results in compiling without errors, but also without barcode. Is there perhaps a potential conflict between one of those packages? babel, amsmath, fullpage, amssymb, amsfonts, index, textcomp, graphicx, tikz, algorithm, algorithmic, wasysym, subfigure? – willeM_ Van Onsem Feb 08 '11 at 11:55
  • 3
    @CommuSoft: You need to run pdflatex with the -shell-escapre option, so that auto-pst-pdf can run the postscript tools. – Martin Scharrer Feb 08 '11 at 12:01
  • @CommuSoft: I don't have most of those packages installed on my system, so I don't know if there's a conflict. Try commenting the \usepackage lines one after the other until you find the offending package. – Jake Feb 08 '11 at 12:10
  • 1
    @martin Scharrer: that indeed did the job. The option to activate was --shell-escape (Linux/Ubuntu 10.10). Thanks. @Jake: I've try to find a conflict but none found. – willeM_ Van Onsem Feb 08 '11 at 12:18
  • @CummuSoft: Sorry for the typo in my last comment. The manual says -shell-escape with one dash, but two are also accepted without error. It's a little confusing, because long options must normally have to dashes. TeXLive even accepts the MikTeX option. – Martin Scharrer Feb 08 '11 at 12:25
  • 2
    The correct bounding box size is (0.7in,0.7in). the bar code has this default size. –  Feb 08 '11 at 12:44
  • @Herbert: Thanks, I've changed the answer accordingly. – Jake Feb 08 '11 at 12:50
  • Is it possible one could only add one barcode. I've analyzed how this works. I think the compiler runs two times, one time rendering the pstricks images. A second time inserting the images in the LaTeX pdf. However if I add two different barcodes. It simply overides the file by the last barcode, and uses this file for both the barcodes. Is there any workaround for this problem? – willeM_ Van Onsem Jul 05 '11 at 00:55
  • @CommuSoft: one pspicture environment - one image. It is not possible that they are overwritten. Give a complete example of what you did. –  Jul 05 '11 at 11:55
  • @Herbert: I simply wrote\begin{pspicture}(0.7in,0.7in}\psbarcode{http://www.ctan.org}{}{qrcode}\end{pspicture} and any further \begin{pspicture}(0.7in,0.7in)\psbarcode{http://www.google.com}{}{qrcode}\end{pspicture} after compiling there was one file created by ps named file-pics.pdf. It only contained one page (barcode). Of course the expected result is two files or two pages in the same pdf. – willeM_ Van Onsem Jul 05 '11 at 22:55
  • @CommuSoft: see my answer, I have no problem. If you have one then give a complete example, as I already wrote! –  Jul 06 '11 at 06:46
7

Take a look at possible packages for typesetting of barcodes at CTAN.

6

Two barcode side by side, run with pdflatex -shell-escape <file>

\documentclass{minimal}
\usepackage[pdf]{pstricks}
\usepackage{pst-barcode}
\begin{document}

\begin{pspicture}(0.7in,0.7in)
\psbarcode{ctan.org}{}{qrcode}
\end{pspicture}
%
\begin{pspicture}(0.7in,0.7in)
\psbarcode{tug.org}{}{qrcode}
\end{pspicture}

\end{document}

enter image description here