# Generating QR-code in header impossible?

I've got a strange issue with the packages pstricks/pst-barcode and fancyhdr. Here is what I like to do: A custom header for every page, Name on the left, QR-code on the right.

Although the QR-code generated without any problems when I first tested it inside the page, it won't do if I put it into fancyheader. Although I searched and tried to find some solution for the last few hours, but I am still stucked. Does anybody know if here is an issue or a work around?

Errors are:

• Warning line 1 Package auto-pst-pdf Warning: Creation of gesamt6-autopp.dvi failed

• Warning line 1 Package auto-pst-pdf Warning: Could not create gesamt6-pics.pdf. Auxiliary files are not deleted.

Here is what the problematic code looks like (reduced):

\documentclass[11pt,a4paper]{scrlttr2}
\usepackage[english,ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{pst-barcode}
\usepackage[notightpage]{auto-pst-pdf}
\usepackage{pstricks}

\pagestyle{fancy}
\fancyhf{}

\newcommand\surname         {Somefamily}
\newcommand\firstname       {Somename}

\begin{pspicture}(20mm,20mm)% save the space
\psbarcode{MECARD:N:\surname,\ \firstname;ADR:\street,\ \streetnumber,\ \zip,\ \country;TEL:\phoneprefix\phone;EMAIL:\mail;;}{eclevel=H width=1.0 height=1.0}{qrcode}
\end{pspicture}}

\begin{document}
Some text
\end{document}

-
If auto-pst-pdf does some automagic conversion of pstricks to pdf, then it well may choke on PSTricks in the header. I suggest to pre-generate the QR-code in a \savebox and \usebox that box in the header. –  Stephan Lehmke Sep 17 '12 at 12:07

As Stephan Lemke suggests, here is a working version:

\documentclass{article}
\usepackage{fancyhdr,textpos,lipsum,pst-barcode,auto-pst-pdf}
\pagestyle{fancy}
\fancyhf{}

\newcommand\surname{Somefamily}
\newcommand\firstname{Somename}
\newcommand\street{Somestreet}
\newcommand\zip{12345}
\newcommand\streetnumber{42}
\newcommand\country{Noland}
\newcommand\phoneprefix{555}
\newcommand\phone{555-5555}
\newcommand\mail{a@n.l}

\newsavebox{\CARD}

\begin{document}

\sbox{\CARD}{%
\begin{pspicture}(20mm,20mm)% save the space
TEL:\phoneprefix\phone;EMAIL:\mail;;}{eclevel=H width=1.0 height=1.0}{qrcode}
\end{pspicture}}

\lipsum
\end{document}


Note that the box must be built after \begin{document}.

-

run it with xelatex and everything will be fine:

\documentclass[11pt,a4paper]{scrlttr2}
\usepackage{fontspec}
\setmainfont{Bera Serif}
\usepackage[english,ngerman]{babel}
\usepackage{fancyhdr}
\usepackage{pst-barcode,textpos}
\usepackage{pstricks}

\pagestyle{fancy}
\fancyhf{}

\newcommand\surname         {Somefamily}
\newcommand\firstname       {Somename}
\def\street{Street}
\def\streetnumber{12}
\def\zip{12345}
\def\country{USA}
\def\phoneprefix{001}
\def\phone{12346}
\def\mail{abc.org}