We can use \special{pdf: code ...} operator or \pdfliteral{} operator. Zdeněk Wagner, a Czech TeXist, mentions some technical details in the Zpravodaj journal 1/2013 of the Czechoslovak TeX Users Group.
I like a new toy named pdf-trans and those examples created by Paweł Jackowski. I illustrate the use of the \boxgs command. I also like another preprepared commands, e.g. \boxshow and \boxmarkers, so I added them to that example even if they are not directly related to the Question.
The Tr operator is selecting the method of displaying a font (0, 1, or 2) with q operator which must be paired with Q operator to fit Adobe PDF specifications. It is not easy to describe these operators in detail. Then, we use w operator (dimension in big points) to set width of outline curves and the rest is easy. We set colors for font and its outline by rg&RG (rgb), k&K (cmyk) or g&G (gray). We usually use numbers before its operator, the PostScript users already know that.
I enclose an example where I set red font and sort of green outline, width is 3bp (it is very close to 3pt).
%! {pdf|lua}latex mal-outline.tex
\documentclass[a4paper]{article}
\usepackage{tikz}
\pagestyle{empty}\parindent=0pt
\input pdf-trans
\newbox\qbox
\begin{document}
\huge
\def\maltext{An example.}
\setbox\qbox=\hbox{\maltext}%
\begin{tikzpicture}
\node[align=center, draw]{%
\boxgs{Q q 2 Tr 0.3 w 0.47 0.6157 0.38 RG 1 0 0 rg }{}%
\copy\qbox \\
\boxshow{0.3 w 0 0 1 RG}{[1 1]0 d}{}
\copy\qbox \\
\boxmarkers{-12pt}{3pt}{0.3 w 1 0 0 RG 1 J}
\copy\qbox
};
\end{tikzpicture}
%\normalsize Text continues here.
\end{document}

contourpackage. Thanks for mentioning it. – Gonzalo Medina May 17 '11 at 19:09rounded cornersfor a little extra elegance? – Andrew Stacey May 17 '11 at 20:42contourdoes not (yet?) work with XeTeX :( – Sean Allred Dec 24 '16 at 06:10