1

My aim is to produce a pdf file (letter) with an included metadata stream for later indexing purposes. The tex-file gets created by a program and the compilation should be possible by three major engines: pdfLaTeX, LuaLaTeX and XeTeX.

The problem is, that this approach needs definitly the xml stream object in the pdf file and not only the pdf info dictionary. The PDFINFO dict is created fine by all three engines, but when the metadata stream should appear, nothing happens when using XeLaTeX.

Question
My question is what i am doing wrong, or is this a limitation of XeTeX?

I prepared a MWE for testing:

% testmeta.tex
\documentclass[10pt]{letter}
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
\else
\usepackage{fontspec}
\fi
\ifLuaTeX
  \usepackage{luatex85} % defines pdfinfo
\fi
\usepackage[bookmarks=false]{hyperref} % i don't want bookmarked letters
\usepackage{hyperxmp}
%%
%% the following creates the pdf DOCINFO dict fine in any case:
%%
\ifXeTeX
\special{pdf: docinfo <<
\else
  \pdfinfo {
\fi
  /Language (en-US)
  /Title (This Is The Title)
  /Author (Jane Doe)
  /Creator (SmartProgram using LaTeX)
  /Subject (Test for inclusion of a metadata stream)
  /Identifier (uuid:43b6b493-42ea-489d-9a04-db20596c4fd7)
  /CreationDate (D:20220420090513+02'00')
  /Keywords (Metadata-Inclusion, Smart Program, TeX, Test)
\ifXeTeX
>>}
\else }
\fi

%% the following creates a pdf xml stream object when compiled with pdfTeX or LuaTeX
%% but not with XeTeX:

\hypersetup{
   keeppdfinfo,  % suggestion from hyperxmp doc to keep the pdf info dictionary above
   pdflang={en-US},
   pdfmetalang={en-US},
   pdftitle={This Is The Title},
   pdfauthor={Jane Doe},
   pdfcreator={SmartProgram using LaTeX},
   pdfsubject={Test for inclusion of a metadata stream},
   pdfdocumentid={43b6b493-42ea-489d-9a04-db20596c4fd7},
   pdfcreationdate={D:20220420090513+02'00'},
   pdfkeywords={Metadata-Inclusion, Smart Program, TeX, Test},
}

\begin{document}

\begin{letter}{FirstName LastName\\ 123 Street\\ Town 54321-0123\\ WHEREVER}

\opening{Dear Mrs. LastName}

Text Text Text

\closing{With kind regards}

\end{letter}

\end{document}

To extract the pdf information i used the cli program 'pdfinfo' supplied by the 'poppler' library. To inspect the pdf files, i used the pdf toolkit program pdftk-java, and i cannot find a xml-data stream when the output engine is XeTeX.

The file 'testmeta.tex' was compiled with pdfLaTeX, LuaLaTeX and XeLaTeX and this is the output from pdfinfo: (all: means identical output from all three engines)

Common metadata:

pdfinfo testmeta.pdf (shortened output)

all:
Title: This Is The Title
Subject: Test for inclusion of a metadata stream
Keywords: Metadata-Inclusion, Smart Program, TeX, Test
Author: Jane Doe
Creator: SmartProgram using LaTeX

with pdfLaTeX and LuaLaTeX:

Producer: pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022) kpathsea version 6.3.4
Producer: LuaHBTeX, Version 1.15.0 (TeX Live 2022)
CreationDate: Wed Apr 20 09:05:13 2022 CEST
ModDate: Sun Apr 24 10:29:55 2022 CEST
Custom Metadata: yes
Metadata Stream: yes <--

with XeTeX:

Producer: XeTeX version 0.999994
CreationDate: Wed Apr 20 09:05:13 2022 CEST
Custom Metadata: yes
Metadata Stream: no <--

I am working on macOS 12.3.1
The output of xetex -version:

XeTeX 3.141592653-2.6-0.999994 (TeX Live 2022)
kpathsea version 6.3.4
Copyright 2022 SIL International, Jonathan Kew and Khaled Hosny.
There is NO warranty.  Redistribution of this software is
covered by the terms of both the XeTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the XeTeX source.
Primary author of XeTeX: Jonathan Kew.
Compiled with ICU version 70.1; using 70.1
Compiled with zlib version 1.2.11; using 1.2.11
Compiled with FreeType2 version 2.11.1; using 2.11.1
Compiled with Graphite2 version 1.3.14; using 1.3.14
Compiled with HarfBuzz version 3.4.0; using 3.4.0
Compiled with libpng version 1.6.37; using 1.6.37
Compiled with pplib version v2.05 less toxic i hope
Using Mac OS X Core Text and Cocoa frameworks

Thank you in advance for your help

2
  • hm, the problem is specific to letter. That needs some investigation. Apr 24 at 12:05
  • @Ulrike Fischer as you commented, i tried using article and scrartcl classes and the metadata stream appears with xetex. My original file uses the scrlttr2 class and there is no metada stream.
    – joHub
    Apr 24 at 13:24

1 Answer 1

1

It is a bug in hyperxmp. It executes the code in \AtEndDocument, but if the document ends with a \pagebreak (as it does with letter) this is on a page that is never shipped out and so the special code is lost.

The correct hook for dvi based formats would be shipout/lastpage:

\documentclass{article}

\usepackage{hyperxmp}
\usepackage{kantlipsum}

\usepackage[]{hyperref}

\hypersetup{
   pdfauthor={Jane Doe},
   pdftitle={A test of metadata},
   }

\makeatletter
\AddToHook{shipout/lastpage}{\hyxmp@construct@packet\hyxmp@embed@packet@xetex}
\makeatother
\begin{document}
\showoutput
abc

\pagebreak

\end{document}

Side remark: Do not fill the info dictionary manually with \pdfinfo. With pdflatex you are actually producing this with your code:

 /Language (en-US) 
 /Title (This Is The Title) 
 /Author (Jane Doe) 
 /Creator (SmartProgram using LaTeX) 
 /Subject (Test for inclusion of a metadata stream) 
 /Identifier (uuid:43b6b493-42ea-489d-9a04-db20596c4fd7) 
 /CreationDate (D:20220420090513+02'00') 
 /Keywords (Metadata-Inclusion, Smart Program, TeX, Test) 

/Author(\376\377\000J\000a\000n\000e\000\040\000D\000o\000e)
/Title(\376\377\000T\000h\000i\000s\000\040\000I\000s\000\040\000T\000h\000e\000\040\000T\000i\000t\000l\000e)
/Subject(\376\377\000T\000e\000s\000t\000\040\000f\000o\000r\000\040\000i\000n\000c\000l\000u\000s\000i\000o\000n\000\040\000o\000f\000\040\000a\000\040\000m\000e\000t\000a\000d\000a\000t\000a\000\040\000s\000t\000r\000e\000a\000m)/Creator(\376\377\000S\000m\000a\000r\000t\000P\000r\000o\000g\000r\000a\000m\000\040\000u\000s\000i\000n\000g\000\040\000L\000a\000T\000e\000X)
/CreationDate(D:20220420090513+02'00')
/Producer(pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022) kpathsea version 6.3.4)
/Keywords(\376\377\000M\000e\000t\000a\000d\000a\000t\000a\000-\000I\000n\000c\000l\000u\000s\000i\000o\000n\000,\000\040\000S\000m\000a\000r\000t\000\040\000P\000r\000o\000g\000r\000a\000m\000,\000\040\000T\000e\000X\000,\000\040\000T\000e\000s\000t)

As you can see various entries (e.g. /Title and /Author) are twice in the dictionary and that is invalid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.