# Turkish character problem when using pdfinfo,trying to get title with pdfrw module of python

I am basically trying to add metadata, especially title to pdf by using pdfinfo as follows:

\documentclass{article}
\usepackage[utf8]{inputenc}

\title{Türkçe Karakter İçeren Başlık}
\author{Abdullah UYU}
\date{4 Mart 2018}

\pdfinfo{
/Author (Abdullah UYU)
/Title  (Türkçe Karakter İçeren Başlık)
}

\begin{document}

\maketitle
Yazı

\end{document}


And in python I am trying to get title like this:

And if I remove the Turkish characters like this:

\documentclass{article}
\usepackage[utf8]{inputenc}

\title{Türkçe Karakter İçeren Başlık}
\author{Abdullah UYU}
\date{4 Mart 2018}

\pdfinfo{
/Author (Abdullah UYU)
/Title  (Turkce Karakter Icermeyen Baslik)
}

\begin{document}

\maketitle
Yazı

\end{document}


I get expected result:

• Some related questions: tex.stackexchange.com/q/50864/134144 and tex.stackexchange.com/q/12981/134144 (if you want to use hyperref). – leandriis Mar 4 '18 at 11:01
• As far as I understand, there is no way to give unicode parameter to pdfinfo. On the other hand, with hyperref it's possible. After trying it, I got a meaningless string in python, but using decode function gave the desired string. @leandriis – user137084 Mar 4 '18 at 11:23

## 1 Answer

PDF bookmarks only understand the encodings PdfDocEncoding (8-bit) and Unicode as UTF16BE-BOM. But the input encoding of the input is UTF-8.

Package hyperref does the necessary conversions from UTF-8 to UTF16BE and adds the BOM:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[pdfencoding=auto, pdfusetitle]{hyperref}

\title{Türkçe Karakter İçeren Başlık}
\author{Abdullah UYU}
\date{4 Mart 2018}

\begin{document}

\maketitle
Yazı

\end{document}


Option pdfencoding=auto switches to Unicode for the bookmarks and tries to convert to PdfDocEncoding. The result has PdfDocEncoding if it fits the encoding (the supported characters are rather limited) or Unicode if it does not fit.

Option pdfusetitle hacks into \title and \author to get the meta data for the PDF. Alternatively, these entries can be set manually:

\hypersetup{
pdftitle={Türkçe Karakter İçeren Başlık},
pdfauthor={Abdullah UYU},
}


The PDF file contains:

/Author (Abdullah\040UYU)
/Title (\376\377\000T\000\374\000r\000k\000\347\000e\000\040\000K\000a\000r\000a\000k\000t\000e\000r\000\040\001\060\000\347\000e\000r\000e\000n\000\040\000B\000a\001\137\000l\001\061\000k)


The author is encoded in PdfDocEncoding and the space in octal notation (\040). It could also be given as (Abdullah UYU). The title is in Unicode as UTF16BE with BOM, the bytes (octets) are then encoded as PDF string with octal escapes for non-ASCII character and problematic ASCII characters.

• I discovered some of the things you said after reading the comment in the main section but didn't know the pdfusetitle option. Actually I used to need it. Thanks! – user137084 Mar 4 '18 at 12:05