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.

Please consider the following MWE, which shall place a QR code (pst-barcode package) at a fixed position on the page using the textpos package:

\documentclass{article}
\usepackage{pst-barcode}
\usepackage[absolute,showboxes]{textpos}
\setlength{\TPHorizModule}{1mm}
\setlength{\TPVertModule}{1mm}
\textblockorigin{0mm}{0mm}

\newcommand{\insertBarcode}{
    \begin{pspicture}(1in,1in)
        \psbarcode{Test}{}{qrcode}
    \end{pspicture}
}

\begin{document}

    \begin{textblock}{75}(80,50)
      Here should be a QR code:\\
      \insertBarcode\\
      But there is none.
    \end{textblock}

    \vspace*{50mm}
    W/o being placed in a \texttt{texblock} environment, the QR code will show up:\\
    \insertBarcode

\end{document}

If this document is compiled with XeLaTeX (MikTeX), the QR code within the normal page content is displayed without any problems. But the one enclosed in the textblock environment won't show up.

I get the following warning:

MiKTeX GPL Ghostscript  9.00: Unrecoverable error, exit code 1

** WARNING ** Filtering file via command -->mgs.exe -q -dNOPAUSE -dBATCH -sPAPERSIZE=a0 -sDEVICE=pdfwrite -dCompatibilityLevel=1.3 -dAutoFilterGrayImages=false -dGrayImageFilter=/FlateEncode -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -dUseFlateCompression=true -sOutputFile="mik56F0.tmp" "mik56EF.tmp" -c quit<-- failed.
** WARNING ** Image format conversion for PSTricks failed.
** WARNING ** Interpreting special command pst: (ps:) failed.
** WARNING ** >> at page="1" position="(226.77, 618.307)" (in PDF)
** WARNING ** >> xxx "pst:  tx@Dict begin STP newpath 0.8 SLW 0  setgray   gsave 0.  "

Using LaTeX -> dvi2ps -> ps2pdf, the QR code will show up as intended.

So my question is: Is it possible to place barcodes from the pst-barcode package within a textblock environment using XeLaTeX (MikTeX)?

I would appreciate any help.

share|improve this question
    
Thank you both Higgs Boson and Ulrike Fischer for your answers and elaborations concerning my problem definition above. I think both solution suggestions are unsatisfactory, but not because of their quality, but rather because there seems to be a conflict between all actors in the XeLaTeX <> PostScript <> pst-barcode chain, which can't be solved on the end-user's side. Having said this, I decided to choose Higgs Boson's solution as accepted answer, since the question was how to place barcodes from the pst-barcode package within a textblock environment. Again, thank you both. –  DigNative Aug 2 '12 at 10:55

2 Answers 2

up vote 1 down vote accepted

Compile it with either pdflatex --shell-escape mainfilename.tex or xelatex --shell-escape mainfilename.tex.

\documentclass{article}
\usepackage{filecontents}

\begin{filecontents*}{temporary.tex}
\documentclass[border=0pt,pstricks]{standalone}
\usepackage{pst-barcode}
\begin{document}
       \begin{pspicture}(1in,1in)
        \psbarcode{Test}{eclevel=L width=1 height=1}{qrcode}
    \end{pspicture}
\end{document}
\end{filecontents*}

\begin{filecontents*}{another.tex}
\documentclass[border=0pt,pstricks]{standalone}
\usepackage{pst-barcode}
\begin{document}
       \begin{pspicture}(1in,1in)
        \psbarcode{Another}{eclevel=L width=1 height=1}{qrcode}
    \end{pspicture}
\end{document}
\end{filecontents*}

\def\attach#1{%
\immediate\write18{latex #1}% you can replace it with xelatex but don't forget to comment the following dvips and ps2pdf.
\immediate\write18{dvips #1}%
\immediate\write18{ps2pdf #1.ps}%
\includegraphics{#1}}

\usepackage[absolute,showboxes]{textpos}
\setlength{\TPHorizModule}{1mm}
\setlength{\TPVertModule}{1mm}
\textblockorigin{0mm}{0mm}

\usepackage{graphicx}

\begin{document}

\begin{textblock}{75}(80,50)
Here should be a QR code:
    \begin{center}
        \attach{temporary}
    \end{center}
But there is none.
\end{textblock}


\vspace*{50mm}
W/o being placed in a \texttt{texblock} environment, the QR code will show up:\\
\attach{another}

\end{document}
share|improve this answer
    
Hi, thank you for your answer. Admittedly, the above code works and solves the issue, but it is not really graceful. Is there no other option? –  DigNative Jul 30 '12 at 15:03
    
@saint: Yes. There is. Put each barcode code in a separate but compilable file, compile it with latex-dvips-ps2pdf, and attach the resulting PDF file to your main input file and finally compile the main input file with pdflatex. –  stalking is prohibited Jul 30 '12 at 15:05
1  
For several reasons I have to use xelatex, so compiling with pdflatex is not an option. I think you will admit that preparing a separate file and have a dedicated compiler run for each barcode to be used isn't an perfect solution in front of placing a QR code by just entering \psbarcode{text}{}{qrcode} in normal text. BTW: Why is the barcode shown correctly in the continuous text, but not in the textblock environment? For me there is no obvious reason for replacing the barcode within the continuous text with this workaround, if the barcode is rendered correctly with xetex. –  DigNative Jul 30 '12 at 15:12
    
@saint: Compiling the main input file with xelatex is ok. But you will not get the full benefit of using microtype package that is fully supported for pdflatex. Separating each diagram in a single compilable input file and running it separately are a good practice. Because you will easily locate the source of problem, you will not be distracted with lengthy code in your main input file, you will not interfere one definition with other definitions, etc, etc. –  stalking is prohibited Jul 30 '12 at 15:20
1  
Your points are understandable, but instead of using a single line of code (\psbarcode{text}{}{qrcode}) this kind of solution seems to break a butterfly on a wheel. I would be rather interested in why the barcode is rendered correctly within the continuous text, but fails in rendering within the textblock environment. I mean it is working with pdflatex, why doesn't it work with xelatex? –  DigNative Jul 30 '12 at 15:36

It looks as if xelatex chokes over postscript which needs to be processed at shipout time (it needs to call ghostscript to convert the ps and this can fails in complicated situations). With eso-pic there is the same problem. Imho you should generate pdf-files of your barcodes.

You can try the externalize library of tikz (you need to use xelatex --shell-escape) to do it automatically:

\documentclass[]{scrartcl}
\usepackage{pst-barcode}
\usepackage{tikz}

\usetikzlibrary{external}
\tikzset{external/system call={xelatex --jobname="\image"
"\texsource"}}

\tikzexternalize
\newsavebox\mybarcode

\begin{document}
some text
%\tikzset{external/force remake}
\tikzsetnextfilename{mybarcode}
\savebox\mybarcode{%
 \begin{tikzpicture}
 \node{\begin{pspicture}(1in,1in)
         \psbarcode{Test}{}{qrcode}
       \end{pspicture}};
 \end{tikzpicture}}

\IfFileExists{mybarcode.pdf}{\includegraphics{mybarcode}}

\end{document}
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.