A report opens under its old title even though the metadata panel shows the new one. The title lives in two places, the Info dictionary and the XMP packet, and the two can disagree. With PDFlibPas you can reopen the file in Delphi, compare the Info title with the XMP title, and check the DisplayDocTitle preference that tells a viewer whether to show the document title or the file name.
Which title does a PDF reader use?
The answer changes between PDF 1.7 and PDF 2.0. ISO 32000-1 and ISO 32000-2:2020 both describe /DisplayDocTitle in §12.2, and in both the file name is the choice when the preference is false, the default. They disagree on the title itself: ISO 32000-1 points the window title bar to the Info dictionary's /Title entry, whilst ISO 32000-2:2020 points it to dc:title in the XMP stream. A browser tab is different again. Its label can come from the URL or from a download name supplied by the host application, so before you touch the PDF, find out which of these labels the person is actually looking at. The ISO 32000 editions collected by the PDF Association in its specification archive are the place to check the wording for yourself.
Start with three different strings. The file is named two-titles.pdf, Quarterly energy report goes to Info, and Energy use, Q3 goes to XMP. Every label you see now has one source. If the two metadata values happen to match, a title bar that shows them says very little about which one the viewer read. A fourth label is the page-one heading. It belongs to the page content and stays as it was, and a stale-looking heading calls for a content edit even when all the metadata reads correctly.
| Reported label | Where it comes from | What to compare |
|---|---|---|
| Quarterly energy report | The example's Info /Title | Compare the title line from GetInformation with the legacy viewer's window title |
| Energy use, Q3 | The example's XMP dc:title | Compare the title bar with the default or selected language alternative in the XMP packet |
| two-titles.pdf | The output's file name | Check the saved preference and distinguish a desktop window title from a browser or application tab |
| The heading on page one | Page content, such as a painted text run or text included in an image | Open the first page and compare the visible heading with the report source |
What does XMP store beyond the Info dictionary?
Info holds a single text string for each of /Title and /Author. XMP stores the title as a set of language alternatives and the creators as an ordered list. A dashboard may need one report title and one display author, whilst a records system may need the report's French title and the names of every contributor. In a multilingual workflow, one default language alternative therefore goes into the single Info title and the localised variants stay in XMP. Creator order can carry credit. For that reason, the value the dashboard takes from the list should be decided before the list is flattened into one Info string. Adobe's Dublin Core namespace reference defines the property types.
<dc:title>
<rdf:Alt>
<rdf:li xml:lang="x-default">Energy use, Q3</rdf:li>
<rdf:li xml:lang="en">Energy use, Q3</rdf:li>
<rdf:li xml:lang="fr">Consommation d'énergie au T3</rdf:li>
</rdf:Alt>
</dc:title>
<dc:creator>
<rdf:Seq>
<rdf:li>Building Analytics</rdf:li>
<rdf:li>Facilities Research</rdf:li>
</rdf:Seq>
</dc:creator>
The fragment shows the shape of the data inside rdf:Description. The x-default entry provides the default text, and each named language gets its own rdf:li. The order of an rdf:Seq is meaningful. One easy mix-up here is matching /Author to xmp:CreatorTool, which describes software such as the report generator. The people or organisations responsible for the document belong in dc:creator. The prefix is not fixed either. An external producer may use a prefix other than dc for the same Dublin Core namespace, so a parser that reads such packets should match XML elements by namespace URI and local name.
ISO 32000-2:2020 §14.3.3 deprecates the Info dictionary for general document metadata, apart from the creation and modification dates. Section 14.3.2 describes the metadata streams that should be used instead, including the stream attached to an entire document. For a new PDF 2.0 workflow, the packet is therefore the primary place for descriptions, credits, and translations. The Info fields in the example are there for customers who also open the reports in older software. Title language still belongs in the XMP entries when the report carries a document language for its page content. The two describe different things. A French-language report may include an English catalogue title.
How do you write Info, XMP and the viewer preference in Delphi?
For an ordinary report with one title and one author, the same public title goes to Info and to XMP, so both generations of viewers have one value to display. The PDFlibPas routine below takes one extra argument. It lets you put a different title in XMP for the two-title copy. Order matters. By default, SetInformation also updates its corresponding XMP property, so calling it after the XMP override would replace the second title. SetXMPProperty targets the packet. For the viewer preference, 6 is DisplayDocTitle and 1 turns it on. 5 is CenterWindow. The viewer preference reference in the PDFlibPas documentation lists all sixteen options with their numbers.
uses
SysUtils, PDFlibrary;
const
InfoAuthor = 1;
InfoTitle = 2;
DisplayDocTitle = 6;
procedure RequireSuccess(Status: Integer; const Operation: string);
begin
if Status <> 1 then
raise Exception.CreateFmt('%s failed', [Operation]);
end;
procedure SaveReportMetadata(const InputFile, OutputFile, PacketTitle: WideString);
const
ReportAuthor = 'Building Analytics';
ReportTitle = 'Quarterly energy report';
var
PDF: TPDFlib;
begin
PDF := TPDFlib.Create;
try
RequireSuccess(PDF.LoadFromFile(InputFile, ''), 'LoadFromFile');
RequireSuccess(PDF.SetInformation(InfoAuthor, ReportAuthor), 'Set Info author');
RequireSuccess(PDF.SetInformation(InfoTitle, ReportTitle), 'Set Info title');
RequireSuccess(PDF.SetXMPProperty('dc', 'creator', ReportAuthor),
'Set XMP creator');
RequireSuccess(PDF.SetXMPProperty('dc', 'title', PacketTitle), 'Set XMP title');
RequireSuccess(PDF.SetViewerPreferences(DisplayDocTitle, 1),
'Set DisplayDocTitle');
RequireSuccess(PDF.SaveToFile(OutputFile), 'SaveToFile');
finally
PDF.Free;
end;
end;
The input is any unencrypted report with at least one page, saved as input.pdf. The output goes to a different path. SaveReportMetadata('input.pdf', 'two-titles.pdf', 'Energy use, Q3') produces the two-title copy. With Quarterly energy report as the third argument the titles match, and for a generated report on its way out I would pick one name in the report definition and use it for both fields. The paired write keeps ordinary desktop viewers and XMP-based catalogues in agreement without depending on how either one resolves a conflict. The routine has one limit. A single-value setter replaces the whole property. Translated titles or several creators already in the input do not survive that setter. To keep them, edit the packet with a namespace-aware XML or XMP tool and write the updated packet back with SetDocumentMetadata.
Reading the saved values back from the file
The routine below reopens the output in a fresh TPDFlib instance and prints five lines: the Info title, the Info author, the XMP title, the XMP creator and the DisplayDocTitle flag. It reuses RequireSuccess and the three constants from the first listing. GetXMPProperty reads only a single XMP value for each property, which suits the file just generated.
procedure ReadSavedReport(const FileName: WideString; DumpPacket: Boolean);
var
PDF: TPDFlib;
begin
PDF := TPDFlib.Create;
try
RequireSuccess(PDF.LoadFromFile(FileName, ''), 'Reload report');
WriteLn('Title from GetInformation: ', PDF.GetInformation(InfoTitle));
WriteLn('Author from GetInformation: ', PDF.GetInformation(InfoAuthor));
WriteLn('XMP title: ', PDF.GetXMPProperty('dc', 'title'));
WriteLn('XMP creator: ', PDF.GetXMPProperty('dc', 'creator'));
WriteLn('DisplayDocTitle: ', PDF.GetViewerPreferences(DisplayDocTitle));
if DumpPacket then
WriteLn(PDF.GetDocumentMetadata);
finally
PDF.Free;
end;
end;
Expected output from ReadSavedReport('two-titles.pdf', False):
Title from GetInformation: Quarterly energy report
Author from GetInformation: Building Analytics
XMP title: Energy use, Q3
XMP creator: Building Analytics
DisplayDocTitle: 1
The two title lines differ by design. SaveReportMetadata wrote the title and the author into the Info dictionary. On an arbitrary PDF without an Info dictionary, GetInformation can fall back to XMP for those fields, and an equal pair of results can then come from a single source. To establish that a physical Info entry exists, open the file in a tool that lists the trailer and look for /Info.
All five lines can be right and a desktop viewer may still show the file name. The next step isolates the flag. Pass 0 to SetViewerPreferences in place of 1, save a third copy with the metadata unchanged, and open both files in that viewer, in windows of one kind. A difference controlled by that one flag points to the viewer's own setting. A browser embedding both files under one page title may give them identical tab labels. The comparison narrows the question down before someone changes the report title again. The preference getter has one blind spot. It returns zero for an explicit false value. It returns zero for a missing Boolean entry too, and both lead to the default behaviour described by ISO 32000. A job that must tell an omitted preference from a stored false has to read the /ViewerPreferences dictionary in the catalog itself.
External files deserve the whole packet. Pass True as the second argument of ReadSavedReport and it appends the output of GetDocumentMetadata, where the language alternatives and the creator sequence can be inspected directly. A plain string search can match a word in an unrelated property, and a successful title lookup tells you nothing about a second language or the order of two authors. Two related articles go further. The article on why a no-op PDF save can rewrite Info and XMP metadata shows what has to survive when a job saves a file without editing it, and how to compare the two files. The article on converting a PDF to PDF/A and repairing its metadata covers the extra rules a PDF/A validator applies when Info and XMP disagree, and RepairDocumentMetadata, which makes the two agree. The five printed lines tell you what title data went into the delivered file. What each viewer does with that data stays visible in its own title bar.
Whenever a desktop viewer and an XMP-based catalogue show different titles, start with the two-title copy. For the other viewer preferences, see the product page for PDF Library for Delphi.