Package hyperref
hyperref
encodes correctly, but the options should be set after hyperref
is loaded. Otherwise LaTeX expands the options the hard way and hyperref
will only see the expanded garbage.
\usepackage{hyperref}
\hypersetup{
pdfauthor={Erwin Schrödinger},
}
Extended example:
\documentclass{article}
\usepackage[utf8]{inputenc}% utf8, for example
\usepackage[
pdfencoding=auto,% or unicode
psdextra,
]{hyperref}
\hypersetup{
pdfauthor={Erwin Schrödinger},
}
\begin{document}
\null
\end{document}
The meta data strings are encoded in PDFDocEncoding or UTF-16BE with BOM in the PDF file. Full power of Unicode for the meta data and bookmarks are enabled by the following hyperref
options:
\usepackage[
pdfencoding=auto,% or unicode
psdextra,
]{hyperref}
pdfencoding=auto
is more flexible than unicode
. If the string fits the PDFDocEncoding (an 8-bit encoding), then this encoding is used, otherwise Unicode.
Low level, manually
The low level version for specifying the meta data with pdfTeX and without hyperref
would look like:
\pdfinfo{/Author(Erwin Schr\string\366dinger)}
The Unicode variants:
\begingroup
\escapechar=`\\
\edef\.{\string\000}%
\pdfinfo{/Author(\string\376\string\377% BOM
\.E\.r\.w\.i\.n\. \.S\.c\.h\.r\.\string\366\.d\.i\.n\.g\.e\.r)}%
\endgroup
or as hexadecimal string:
\pdfinfo{/Author}
The PDF specification tells, which encoding can be used, PDFDocEncoding is listed as full table in Annex D "Character Sets and Encodings".
Low level, but with automatic encoding conversions
If you want to convert from UTF-8 (or other input encoding), then package stringenc
helps
(LaTeX and plain TeX formats):
Plain TeX example:
% UTF-8 encoded source file
\input stringenc.sty\relax
\def\MyAuthor{Erwin Schrödinger}
\edef\BOM{\string\376\string\377}
\StringEncodingConvert{\PdfAuthor}{\MyAuthor}{utf8}{utf16be}
\StringEncodingSuccessFailure{}{%
\errmessage{Conversion from utf8 to utf16be failed for author string}%
}
\pdfinfo{/Author(\BOM\pdfescapestring{\PdfAuthor})}%
\null
\bye
A more elaborate example, reimplementing pdfencoding=auto
:
% UTF-8 encoded source file
\input stringenc.sty\relax
\def\GeneratePdfString#1#2{%
\StringEncodingConvertTest{#1}{#2}{utf8}{pdfdoc}{%
% Success: \PdfAuthor with PDFDocEncoding
% Make full PDF string inclusive brackets
\edef#1{(\pdfescapestring{#1})}%
}{%
\StringEncodingConvert{#1}{#2}{utf8}{utf16be}%
\StringEncodingSuccessFailure{%
% Success: \PdfAuthor with UTF-16BE
}{%
\errmessage{Conversion from utf8 to utf16be failed for author string}%
}%
% Make full PDF string with BOM for case UTF-16BE
\edef#1{(\BOM\pdfescapestring{#1})}%
}%
}
\edef\BOM{\string\376\string\377}%
% Usage
\def\MyAuthor{Erwin Schrödinger}
\GeneratePdfString\PdfAuthor{\MyAuthor}
\GeneratePdfString\PdfTitle{Unicode string example ☺}
\pdfinfo{%
/Author\PdfAuthor
/Title\PdfTitle
}%
\null
\bye
The input need not to be encoding in UTF-8, package stringenc
supports much more encodings.
\documentclass{...}
, the required\usepackage
's,\begin{document}
, and\end{document}
. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.ö
is available in PDFDocEncoding. But LaTeX expands the option before passing it tohyperref
without givinghyperref
the chance to setup the macros for the PDF string conversion and changing the font encoding.