Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The size of 2D barcode depends on the first argument of \psbarcode. I usually do trial and error to find the size of \pspicture such that I get a tight output.

enter image description here

\documentclass{article}

\usepackage{pst-barcode}
\usepackage[active,tightpage]{preview}
\PreviewBorder=1bp
\PreviewEnvironment{pspicture}

\def\s{1.765}% I find this value by trial and error.

\begin{document}

\begin{pspicture}(\s,\s)
    \psbarcode{http://example.org}{eclevel=L}{qrcode}
\end{pspicture}

\end{document}

Is there a "smarter" way to know the size of \psbarcode?

Edit 1: Please make sure you don't remove the preview package and compile it with either latex-dvips-ps2pdf or xelatex.

Edit 2:

\documentclass{article}

\usepackage{pst-barcode}
\usepackage[active,tightpage]{preview}
\PreviewBorder=1bp
\PreviewEnvironment{pspicture}

\usepackage{multido}

\begin{document}

\multido{\n=1.50+0.05}{15}{%
\begin{pspicture}(\n,\n)
        \psframe[linecolor=blue,fillstyle=solid,fillcolor=yellow](\n,\n)
    \psbarcode{http://example.org}{eclevel=L}{qrcode}
    \rput[tr](\n,\n){{\color{red}\n}}
\end{pspicture}}

\end{document}

enter image description here

enter image description here

enter image description here

enter image description here

share|improve this question
    
Changing \s does not have any effect on the output. Please give an example where it has some. Also, how do you create the pdf file? –  canaaerus Jul 10 '12 at 10:52
    
I use exactly your source code. Or is there some more meaning to "using preview"? Ok your edit made it clear. compiling with xelatex did not work. But after applying dvips and ps2pdf the page got smaller. –  canaaerus Jul 10 '12 at 11:07

2 Answers 2

up vote 5 down vote accepted
\documentclass{minimal}
\usepackage{auto-pst-pdf,pst-barcode}
\begin{document}

\fbox{\begin{pspicture}(2in,2in)
    \psbarcode{http://example.org}{eclevel=L width=2 height=2}{qrcode}
\end{pspicture}}

\end{document}

Internally the width/height are used in inch, but you can set this one also on TeX side

enter image description here

share|improve this answer

If you want to have a specific size Hebert's answer is certainly correct. Otherwise you have to calculate, which version of the QR Code has to be used. That depends on the error correction level and the number of bytes you want to store. Assuming you are using level n, the QR Code has a side length of 4n+17 blocks. Each block has a side length of 0.07 which gives you for \s the formula 1.2+0.28n.

According to my tests you will get the following levels with eclevel=L:

0-17 chars – Level 1

18-32 chars – Level 2

33-53 chars – Level 3

54-78 chars – Level 4

This is useful for example if you have QR Codes of different sizes but want them to look homogeneous.

share|improve this answer
    
Nice idea, but unfortunately this isn't quite correct. The internal codeword length isn't a simple function of the input length except for a very constrained domain. –  Terry Burton Jun 25 at 15:43
    
There are several different encoding modes which have different efficiencies for various types of data (alphanumeric, numeric-only, kanji and byte). pst-barcode switches between these modes in order to obtain an optimal encoding (minimum number of codewords), which results in the smallest symbol. The algorithm to achieve this is complex. See the following PostScript: github.com/bwipp/postscriptbarcode/blob/master/src/… –  Terry Burton Jun 25 at 16:01
    
If the worse case for the input data is known, a fixed sized output can be obtained using the version option, e.g. \psbarcode{http://example.org}{eclevel=L version=10}{qrcode}. Otherwise Herbert's solution with variable symbol density is as good as you can hope for (in the general case). –  Terry Burton Jun 25 at 16:05

Your Answer

 
discard

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.