# How to place in a document a VCard using a psbarcode?

I would like to put a QRCode that contains contact information (VCard). However I don't know how to encode the newline character so VCard is correctly read.

Here is a sample document with QRCode without newline chars (UPDATED: I changed the example to one from de.wikipedia.org, because my iphone qrcode reader does not properly processes the example from en.wikipedia.org)):

\documentclass{article}
\usepackage{pst-barcode}

\begin{document}

\begin{pspicture}(1in,1in)
\obeylines
\psbarcode{%
BEGIN:VCARD
VERSION:3.0
N:Mustermann;Max
FN:Max Mustermann
ORG:Wikipedia
URL:http://de.wikipedia.org/
EMAIL;TYPE=INTERNET:max.mustermann@example.org
TEL;TYPE=voice,work,pref:+49 1234 56788
END:VCARD
}{width=2.0 height=2.0}{qrcode}%
\end{pspicture}

\end{document}


I have found a similar question on tug.org, the conclusion was that you need to modify the generated PostScript. I wonder if there is another solution.

Does the following code do the right thing?

\documentclass{article}
\usepackage{pst-barcode}

{\obeylines\gdef^^M{^^J}%
\catcode\@=0 %
\catcode\\=12 %
@gdef@n{\n}}
\begin{document}

\begin{pspicture}(1in,1in)
\obeylines
\psbarcode{%
BEGIN:VCARD
VERSION:3.0
N:Gump;Forrest
FN:Forrest Gump
ORG:Bubba Gump Shrimp Co.
TITLE:Shrimp Man
TEL;TYPE=WORK,VOICE:(111) 555-1212
TEL;TYPE=HOME,VOICE:(404) 555-1212
ADR;TYPE=WORK:;;100 Waters Edge;Baytown;LA;30314;United States of America
LABEL;TYPE=WORK:100 Waters Edge\n Baytown, LA 30314\n United States of America
ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America
LABEL;TYPE=HOME:42 Plantation St.\n Baytown, LA 30314\n United States of America
EMAIL;TYPE=PREF,INTERNET:forrestgump@example.com
REV:20080424T195243Z
END:VCARD
}{width=2.0 height=2.0}{qrcode}%
\end{pspicture}

\end{document}

• I have an additional question. Why the command does not work when I put the pspicture in tabular. – Skarab Jun 12 '11 at 18:37
• @Skarab: That would be because all the tokens going into one tabular entry get scanned before they are executed, and so the category changes happen too late to do any good. You can do \setbox0\hbox{…} where … stands for the entire pspicture environment, and then use \box0 in the tabular. (Note that the standard LaTeX commands \savebox and \sbox also scan their argument before executing, which is why I resort to TeX primitives here.) – Harald Hanche-Olsen Jun 12 '11 at 19:10
• Another solution, which should work without the trick of the previous comment, is to drop the \obeylines and the definition of ^^M and instead manually insert ^^J at the end of each line of the vcard. – Harald Hanche-Olsen Jun 12 '11 at 19:18
• I've implemented, based on the above mentioned example, my own vcard. Can't read it properly for example using MeeScan (ver. 0.0.12). Is it the reader's fault? – Nikos Alexandris Sep 6 '12 at 13:35
• @NikosAlexandris: I have no idea. If other barcode scanners can read it, then yes. Could you tell the difference between a failure to read the scan and a failure to parse the resulting text as a vcard? – Harald Hanche-Olsen Sep 6 '12 at 15:19