How to use \char inside \pdfinfo?

First of all, I would like to avoid hyperref package.

I'm using

\AtEndDocument{
\pdfinfo{
/Title (here (\the\year))
/Creator (foo)
%   /Producer (pdfTeX 1.40.0)
/Author (\@author)
/Subject (foo)
/Keywords (faa,foo)
}
}


to pass some info to the PDF file.

But I also wish to write some chars inside (to be not so explicit), like \char'151\char'141 for example.

But in this case the output is (2016) char '151char '141.

Is it possible to hide chars inside pdfinfo?

• You should either use ^^ notation or \Uchar in LuaTeX (or XeLaTeX). But \char is not expandable. Why exactly do you need that? Can't you define \def\hiddencharone{a} and \def\hiddenchartwo{b} and use \hiddencharone\hiddenchartwo? Oct 10, 2016 at 17:11
• Could you make a better example or is the author's name a secret? Oct 10, 2016 at 17:17
• @egreg, I'd like to make difficulty to students to edit the class and change the meta data. Using those lot of chars could keep the students away. Oct 10, 2016 at 17:29

\char is not an expandable command, thus it does not work as string in \pdfinfo. Also, \char would use the current font encoding. But the font encoding is irrelevant here. Instead, the PDF specification allows two encodings:

• PDFDocEncoding, an 8-bit encoding, different, but similar to latin1,
• UTF16-BE with BOM for Unicode strings

Package stringenc helps in converting a string (e.g. from UTF-8) to the correct encoding, needed for the values in \pdfinfo.

Also the values for the keys in \pdfinfo must be escaped as strings, for example unmatched parentheses; pdfTeX's \pdfescapestring helps here for strings given in parentheses. The other string form are angle brackets with the string encoded as hexadecimal string.

Package hyperref's \pdfstringdef takes care of lots of these issues. It also defines virtual font encodings PD1 and PU to get many characters work. For reinventing the wheel I strongly recommend reading the section about strings in the PDF specification.

At TeX level, the string needs to expand as plain text string without commands. PDF viewers do not know about TeX commands inside bookmark strings.

The letters by \char'151 (i) and \char'141 (a) can be given as (PDFDocEncoding):

\pdfinfo{/Author(\string\151\string\141)}


pdfinfo reports then:

Author: ia

• I'll take a look on those refs. By the way, latin1 is good for me. Thanks. Oct 10, 2016 at 17:31
• @Sigur Some characters are different, the PDFDocEncoding is listed in an appendix of the PDF reference. Oct 10, 2016 at 17:35
• It worked perfectly! I tried \expandafter and \protect without working, thanks to my pour knowledge. But I forgot about \string. Thanks. Oct 10, 2016 at 17:38