[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: printing QR-codes on labels with 300dpi label printers with LaTeX



Hi,

I haven't read the whole thread (sorry) but thought this might help.

hw <hw@adminart.net> wrote:

> When I zoom in on QR-codes in a PDF viewer, they don't get blurry.
> Perhaps the pst-barcode package uses vector graphics?

That is quite likely: the pst- prefix means this is PSTricks, which is
an oldish way of doing vector graphics with LaTeX. I tend to avoid
PSTricks these days as it is generally awkward to use in PDF contexts,
although there are various workarounds that often allow to do so.

The ubiquitous, powerful and modern way to do vector graphics in LaTeX
is PGF/TiKZ[1], however this is not even necessary for QR codes, because
these are made of perfect monochrome rectangles, which TeX can draw
natively using its \hrule and \vrule primitives.

> 'pdfimages -list' doesn't show any images for a PDF with QR-codes
> created with pdflatex.

AFAIK, 'pdfimages' would extract “actual images” embedded in a PDF file
(e.g., PNG or JPG), however here pst-barcode presumably uses PostScript
or PDF primitives for drawing and filling polygons, which in your case
probably end up as PDF primitives. Hence, 'pdfimages' can't see these QR
codes (AFAIUI).

I've played with a different package for producing QR codes in LaTeX,
which uses the aforementioned \hrule and \vrule primitives: qrcode. Its
manual is here (follow the “Package documentation” link):

  https://ctan.org/pkg/qrcode

Here is a simple example you can compile with pdflatex:

\documentclass{article}
\usepackage{qrcode}

\pagestyle{empty}

\begin{document}

\noindent
% \qrset affects \qrcode commands in the current group. You can use it
% to factor out options used for several QR codes.
\qrset{nolinks, padding}% add padding to make sure the codes are “legal”/readable
\qrcode[version=1]{Hey Debian-user!}% Can't do version=1 with level=M or more
\qrcode[level=L, version=1]{Hey Debian-user!}% Less redundancy but is doable

\end{document}

Note the terminal output:

------------------------------------------------------------------------
<QR code requested for "Hey Debian-user!" in version 1-M.>
<Requested QR version '1' is too small for desired text.
Version increased to '2' to fit text.>
<Error-correction level increased from M to Q at no cost.>

<Copying the QR code for "Hey Debian-user!" in version 2-Q as previously calculated.>


<QR code requested for "Hey Debian-user!" in version 1-L.>

<Copying the QR code for "Hey Debian-user!" in version 1-L as previously calculated.>
------------------------------------------------------------------------

There are several quality levels allowing error correction (see the
manual): Low, Medium, Quality, and High. They correspond to 'level'
values L, M, Q, H. Default is M but if the chosen 'version' (which maps
to a specific number of modules) allows for a better level, qrcode
automatically upgrades to the best level possible for the chosen
'version' (which the above log demonstrates for the first QR code).

My example tries to print two QR codes with version=1, which means
21×21 modules (see below). Using the default level (M), this is not
possible for the specified text, therefore the first QR code is drawn as
a version=2 one (i.e., it has 25×25 modules). For the second QR code, I
explicitly ask for level=L which has the worst redundancy for error
correction; this allows "Hey Debian-user!" to be QR-encoded with
version=1, i.e. as a square of 21×21 modules.

The length of what you are encoding obviously dictates which quality
parameters you can afford, so you need to play with actual text for your
application. You can control the size of the QR code with e.g.
\qrcode[height=1cm]{...}. Since the modules are stuck to each other,
once you've determined an appropriate 'version' parameter, you can
easily choose a height that causes the modules to have the exact size
you want in the resulting PDF file (printer driver issues are out of my
league).

Regarding the 'version' parameter:

  version=1  → 21×21 modules
  version=2  → 25×25 modules
  version=3  → 29×29 modules
  ...
  version=40 → 177×177 modules

(each version step adds 4 to the number of modules in each direction)

So, you may want to play with text of yours and these parameters.
Examine the terminal output or log file to make sure the qrcode package
didn't have to increase the 'version' in order to encode the text you
specified. Note that in my example, the second QR code scanned with a
smartphone from a computer screen display seems to be significantly
harder to recognize than the first one (IOW, using level=L is probably a
bad idea even though it allows one to reduce the number of modules. But
with low printer resolution constraints, who knows?).

Hope this helps!

Regards

[1] https://ctan.org/pkg/pgf

-- 
Florent


Reply to: