From eeaea8529472b9610e17f72b1d0e63bd2e069d20 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 21 Dec 2019 17:43:53 +0100 Subject: [PATCH] Re-factor how the viewer title is determined, based on the `Info`/`Metadata` data With these changes we'll always set the `pdfTitle` to the `Info` dictionary entry *first* (assuming it exists and isn't empty), before attempting to override it with the `Metadata` stream entry (assuming it exists, is non-empty *and* valid). There should be no functional changes with this patch, but it will simplify the following patch somewhat. --- web/app.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/web/app.js b/web/app.js index 8c6a202ae..f3a669f30 100644 --- a/web/app.js +++ b/web/app.js @@ -1117,16 +1117,18 @@ let PDFViewerApplication = { (AppOptions.get('enableWebGL') ? ' [WebGL]' : '') + ')'); let pdfTitle; - if (metadata && metadata.has('dc:title')) { - let title = metadata.get('dc:title'); - // Ghostscript sometimes return 'Untitled', sets the title to 'Untitled' - if (title !== 'Untitled') { - pdfTitle = title; - } - } - if (!pdfTitle && info && info['Title']) { - pdfTitle = info['Title']; + const infoTitle = info && info['Title']; + if (infoTitle) { + pdfTitle = infoTitle; + } + const metadataTitle = metadata && metadata.get('dc:title'); + if (metadataTitle) { + // Ghostscript can produce invalid 'dc:title' Metadata entries: + // - The title may be "Untitled" (fixes bug 1031612). + if (metadataTitle !== 'Untitled') { + pdfTitle = metadataTitle; + } } if (pdfTitle) {