From ac33e5984947dbfb601b331a15c73242d657f4d4 Mon Sep 17 00:00:00 2001 From: Ekaterina Chubrick Date: Tue, 16 Jun 2026 14:28:48 +0300 Subject: [PATCH 1/2] Fix issue with names decoding --- src/core/catalog.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/core/catalog.js b/src/core/catalog.js index 17e1e28e10f21..dc7e812eac414 100644 --- a/src/core/catalog.js +++ b/src/core/catalog.js @@ -1798,6 +1798,17 @@ class ExtendedCatalog extends Catalog { return shadow(this, "structTreeRootObject", structTreeRoot); } + convertString(str, type) { + try { + return stringToUTF8String(str); + } catch (e) { + console.log( + `Failed to convert string "${str}" (${type}) to UTF-8, using safe conversion. Error: ${e}` + ); + return stringToPDFString(str); + } + } + getTreeElement(el, page, ref) { try { // update page for current element @@ -1817,8 +1828,8 @@ class ExtendedCatalog extends Catalog { const roleName = this.getRoleName(el, name); const treeElement = { - name: name ? stringToPDFString(name) : null, - roleName: roleName ? stringToPDFString(roleName) : null, + name: name ? this.convertString(name, "Name") : null, + roleName: roleName ? this.convertString(roleName, "Role name") : null, children: this.getTreeElement(el.get("K"), page, el.getRaw("K")), pageIndex: page, ref: ref instanceof Ref ? ref : null, @@ -1829,7 +1840,7 @@ class ExtendedCatalog extends Catalog { alt = el.has("ActualText") ? el.get("ActualText") : null; } if (typeof alt === "string") { - treeElement.alt = stringToPDFString(alt); + treeElement.alt = this.convertString(alt, "Alt"); } return treeElement; @@ -1903,8 +1914,8 @@ class ExtendedCatalog extends Catalog { const roleName = this.getRoleName(el, name); const treeElement = { - name: name ? stringToPDFString(name) : null, - roleName: roleName ? stringToPDFString(roleName) : null, + name: name ? this.convertString(name, "Name") : null, + roleName: roleName ? this.convertString(roleName, "Role name") : null, children: [], pageIndex: page, ref: ref instanceof Ref ? ref : null, @@ -1915,7 +1926,7 @@ class ExtendedCatalog extends Catalog { alt = el.has("ActualText") ? el.get("ActualText") : null; } if (typeof alt === "string") { - treeElement.alt = stringToPDFString(alt); + treeElement.alt = this.convertString(alt, "Alt"); } return treeElement; From b4d7398075428b00d8998d42cf2c506c629fbf82 Mon Sep 17 00:00:00 2001 From: Ekaterina Chubrick Date: Tue, 16 Jun 2026 16:18:19 +0300 Subject: [PATCH 2/2] Comment debug message --- src/core/catalog.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/catalog.js b/src/core/catalog.js index dc7e812eac414..b32ce42d49618 100644 --- a/src/core/catalog.js +++ b/src/core/catalog.js @@ -1802,9 +1802,9 @@ class ExtendedCatalog extends Catalog { try { return stringToUTF8String(str); } catch (e) { - console.log( + /*console.log( `Failed to convert string "${str}" (${type}) to UTF-8, using safe conversion. Error: ${e}` - ); + );*/ return stringToPDFString(str); } }