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.

Using the following LaTeX-Code:

\documentclass[a4paper]{article}

\usepackage[pdf]{pstricks}
\usepackage{pst-barcode}

\begin{document}
  \begin{pspicture}(0.7in,0.7in)
    \psbarcode{01234567890}{eclevel=L}{qrcode}
  \end{pspicture}
\end{document}

and pdflatex with "shell-escape" option

pdflatex -shell-escape QRCode.tex

a PDF containing the QR-Code is created. However, the QR-Code is anti-aliased. How can I turn off anti-aliasing?

I am using MacTeX (TeX-Live 2010) on Mac OS X 10.6

share|improve this question
    
Welcome to TeX.sx! You don't have to sign with your name since it automatically appears in the lower right corner of your post. –  Martin Scharrer Jun 27 '11 at 17:43
3  
AFAIK anti-aliasing is a feature of the PDF viewer and not influenced by LaTeX. You need to manually switch it off in your viewer. See also the related post My pixel perfect picture gets blurry when compiled in LaTeX, which is about images which look blurry. –  Martin Scharrer Jun 27 '11 at 17:48
1  
Another question is why a programmatically generated image is embedded in raster, not vector, format. –  Andrey Vihrov Jul 24 '11 at 12:42

3 Answers 3

The Barcode Writer in Pure PostScript (BWIPP) library that pst-barcode uses would generate matrix-style barcodes using the PostScript imagemask operator which certain viewers (such as Preview on Mac) incorrectly* choose to interpolate.

For a bit of history, BWIPP switched away from the PostScript image operator in version 2008-12-07 because an increasing number of PS and PDF previewers began to interpolate its output. The replacement imagemask operator worked better for a time, but was clearly not perfect, so BWIPP has switched to using a filled path in version 2014-01-06 which should finally resolve the issue.

Until pst-barcode is updated, users who wish to use their existing pst-barcode with the latest version of BWIPP should replace their barcode.pro file with barcode.ps from the monolithic or monolithic-package distribution of BWIPP.

*: An imagemask should be applied as a bitmap stencil mask without "interpolation", unless requested.

share|improve this answer
2  
How to replace barcode.pro on mac: download "postscriptbarcode-monolithic-package-2014-01-19.tgz" (or newer) from github.com/terryburton/postscriptbarcode/releases. then copy the file barcode.ps to /usr/local/texlive/2012/texmf-dist/dvips/pst-barcode/pst-barcode.pro –  Synox Jan 24 at 15:58

AFAIK anti-aliasing is a feature of the PDF viewer and not influenced by LaTeX. You need to manually switch it off in your viewer. See also the related post My pixel perfect picture gets blurry when compiled in LaTeX, which is about images which look blurry.

share|improve this answer
    
I would support this. The example looks very crisp regardless of zoom level on PDF viewer Evince on Ubuntu, for example. –  kongo09 Sep 4 '11 at 11:24
    
When I turn off anti-aliasing in a Mac OS X 10.6 application Preview, it remains almost the same (like a small raster image). Adobe Acrobat 9 Pro produces a clear image (even with anti-aliased text), though. EAN codes, for example, are shown correctly in both viewers. What could be the cause in this case? –  Harold Cavendish Sep 4 '11 at 18:41

Unrecommended way

I would like to share my solution for historical purposes only and as a new version of postscriptbarcode is not a part of the TeX distributions, yet (April 2014). The presented solution in this question works well for me.

I don't want to scare you, especially TeX beginners, but from time to time you might face a serious deadline even when working with TeX. It happened to me in November 2013 when a Mac OS X user complained about barcode preview in PDF and I had two hours to fix it before production and making PDF file publicly available. I needed solution fast and a working one on Windows, Linux and Mac OS X. I was permitted by publisher to use any (dirty) trick.

At that time I found patch for diff but I didn't tested that as there were so many different releases of this project. The official release solving the issue didn't exist at that time. I was thinking to convert the PDF file somehow. I tried Inkscape with no desired success. I had no time for pstoedit experiments.

As a FontForge user I started to think about raster to vector conversion. There are several projects, two major ones are autotrace and potrace. I installed them and started reading documentation followed by my first experiments.

Let me make this story short, I am presenting you a solution right away with GraphicsMagick + autotrace, where:

  • I get PDF version from pst-barcode the usual way (auto-pst-pdf).
  • I convert the temporary file to raster (GraphicsMagick, ImageMagick).
  • I trace the result to a vector format with no background (autotrace). That blue color is set from within TeX to check that there is no white color or other background color. The key value is -corner-surround 1 which helps to find 90 degree corners.
  • I include the result back to the main TeX file if such a result exists (\IfFileExists).

The presented solution works for one page/barcode only, it would require additional setup for a temporary PDF file with more pages/barcodes. In addition to that, it would be possible to do such a conversion on-the-fly (\write18). As I am using primarily 90 degree corners, it may not work for other barcode types.

I run these commands (it works with pdf-, xe- and lualatex; TeX Live):

lualatex --shell-escape mal-qrcode.tex  
gm convert mal-qrcode-pics.pdf mal-qrcode-pics.bmp  
autotrace -output-format pdf -output-file pst-qr.pdf -corner-surround 1 -background-color FFFFFF mal-qrcode-pics.bmp  
pdfcrop --hires --margins 0 pst-qr.pdf mal-qrcode-pics-vector.pdf  
lualatex --shell-escape mal-qrcode.tex  

I enclose the TeX file (mal-qrcode.tex) and a preview of the result in a web browser (Firefox using pdf.js). Picture on left introduces the problem, picture on right shows the solution.

%! *latex mal-qrcode.tex
%   with shell escape on
\documentclass[a4paper]{article}
\pagestyle{empty}
\usepackage{pst-barcode}
\usepackage{auto-pst-pdf}
\pagecolor{blue}
\begin{document}
\def\malfile{mal-qrcode-pics-vector.pdf}
  \begin{pspicture}(0.7in,0.7in)
    \psbarcode{01234567890}{eclevel=L}{qrcode}
  \end{pspicture}
\IfFileExists{\malfile}{\includegraphics{\malfile}}{%
  % The pspicture environment goes here if we want permanent replacement...
  }% End of \IfFileExists...
\end{document}

mwe

share|improve this answer

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.