diff --git a/src/core/catalog.js b/src/core/catalog.js index d66ecb943..30fead7ad 100644 --- a/src/core/catalog.js +++ b/src/core/catalog.js @@ -279,19 +279,18 @@ class Catalog { /* suppressEncryption = */ !this.xref.encrypt?.encryptMetadata ); - if (stream instanceof BaseStream && stream.dict instanceof Dict) { - const type = stream.dict.get("Type"); - const subtype = stream.dict.get("Subtype"); - - if (isName(type, "Metadata") && isName(subtype, "XML")) { - // XXX: This should examine the charset the XML document defines, - // however since there are currently no real means to decode arbitrary - // charsets, let's just hope that the author of the PDF was reasonable - // enough to stick with the XML default charset, which is UTF-8. - const data = stringToUTF8String(stream.getString()); - if (data) { - metadata = new MetadataParser(data).serializable; - } + if ( + stream instanceof BaseStream && + isDict(stream.dict, "Metadata") && + isName(stream.dict.get("Subtype"), "XML") + ) { + // XXX: This should examine the charset the XML document defines, + // however since there are currently no real means to decode arbitrary + // charsets, let's just hope that the author of the PDF was reasonable + // enough to stick with the XML default charset, which is UTF-8. + const data = stringToUTF8String(stream.getString()); + if (data) { + metadata = new MetadataParser(data).serializable; } } } catch (ex) {