@@ -76,7 +76,7 @@ function fetchRemoteDest(action) {
7676 dest = dest . name ;
7777 }
7878 if ( typeof dest === "string" ) {
79- return stringToPDFString ( dest ) ;
79+ return stringToPDFString ( dest , /* keepEscapeSequence = */ true ) ;
8080 } else if ( isValidExplicitDest ( dest ) ) {
8181 return JSON . stringify ( dest ) ;
8282 }
@@ -674,15 +674,17 @@ class Catalog {
674674 for ( const [ key , value ] of obj . getAll ( ) ) {
675675 const dest = fetchDest ( value ) ;
676676 if ( dest ) {
677- dests [ stringToPDFString ( key ) ] = dest ;
677+ dests [ stringToPDFString ( key , /* keepEscapeSequence = */ true ) ] =
678+ dest ;
678679 }
679680 }
680681 } else if ( obj instanceof Dict ) {
681682 for ( const [ key , value ] of obj ) {
682683 const dest = fetchDest ( value ) ;
683684 if ( dest ) {
684685 // Always let the NameTree take precedence.
685- dests [ stringToPDFString ( key ) ] ||= dest ;
686+ dests [ stringToPDFString ( key , /* keepEscapeSequence = */ true ) ] ||=
687+ dest ;
686688 }
687689 }
688690 }
@@ -691,6 +693,11 @@ class Catalog {
691693 }
692694
693695 getDestination ( id ) {
696+ // Avoid extra lookup/parsing when all destinations are already available.
697+ if ( this . hasOwnProperty ( "destinations" ) ) {
698+ return this . destinations [ id ] ?? null ;
699+ }
700+
694701 const rawDests = this . #readDests( ) ;
695702 for ( const obj of rawDests ) {
696703 if ( obj instanceof NameTree || obj instanceof Dict ) {
@@ -1041,7 +1048,8 @@ class Catalog {
10411048 for ( const [ key , value ] of nameTree . getAll ( ) ) {
10421049 const fs = new FileSpec ( value , this . xref ) ;
10431050 attachments ??= Object . create ( null ) ;
1044- attachments [ stringToPDFString ( key ) ] = fs . serializable ;
1051+ attachments [ stringToPDFString ( key , /* keepEscapeSequence = */ true ) ] =
1052+ fs . serializable ;
10451053 }
10461054 }
10471055 return shadow ( this , "attachments" , attachments ) ;
@@ -1055,7 +1063,10 @@ class Catalog {
10551063 const nameTree = new NameTree ( obj . getRaw ( "XFAImages" ) , this . xref ) ;
10561064 for ( const [ key , value ] of nameTree . getAll ( ) ) {
10571065 xfaImages ??= new Dict ( this . xref ) ;
1058- xfaImages . set ( stringToPDFString ( key ) , value ) ;
1066+ xfaImages . set (
1067+ stringToPDFString ( key , /* keepEscapeSequence = */ true ) ,
1068+ value
1069+ ) ;
10591070 }
10601071 }
10611072 return shadow ( this , "xfaImages" , xfaImages ) ;
@@ -1079,7 +1090,10 @@ class Catalog {
10791090 } else if ( typeof js !== "string" ) {
10801091 return ;
10811092 }
1082- js = stringToPDFString ( js ) . replaceAll ( "\x00" , "" ) ;
1093+ js = stringToPDFString ( js , /* keepEscapeSequence = */ true ) . replaceAll (
1094+ "\x00" ,
1095+ ""
1096+ ) ;
10831097 // Skip empty entries, similar to the `_collectJS` function.
10841098 if ( js ) {
10851099 ( javaScript ||= new Map ( ) ) . set ( name , js ) ;
@@ -1089,7 +1103,10 @@ class Catalog {
10891103 if ( obj instanceof Dict && obj . has ( "JavaScript" ) ) {
10901104 const nameTree = new NameTree ( obj . getRaw ( "JavaScript" ) , this . xref ) ;
10911105 for ( const [ key , value ] of nameTree . getAll ( ) ) {
1092- appendIfJavaScriptDict ( stringToPDFString ( key ) , value ) ;
1106+ appendIfJavaScriptDict (
1107+ stringToPDFString ( key , /* keepEscapeSequence = */ true ) ,
1108+ value
1109+ ) ;
10931110 }
10941111 }
10951112 // Append OpenAction "JavaScript" actions, if any, to the JavaScript map.
@@ -1628,7 +1645,10 @@ class Catalog {
16281645 const name = target . get ( "N" ) ;
16291646
16301647 if ( isName ( relationship , "C" ) && typeof name === "string" ) {
1631- attachment = docAttachments [ stringToPDFString ( name ) ] ;
1648+ attachment =
1649+ docAttachments [
1650+ stringToPDFString ( name , /* keepEscapeSequence = */ true )
1651+ ] ;
16321652 }
16331653 }
16341654
@@ -1694,7 +1714,11 @@ class Catalog {
16941714 js = jsAction ;
16951715 }
16961716
1697- const jsURL = js && recoverJsURL ( stringToPDFString ( js ) ) ;
1717+ const jsURL =
1718+ js &&
1719+ recoverJsURL (
1720+ stringToPDFString ( js , /* keepEscapeSequence = */ true )
1721+ ) ;
16981722 if ( jsURL ) {
16991723 url = jsURL . url ;
17001724 resultObj . newWindow = jsURL . newWindow ;
@@ -1730,7 +1754,10 @@ class Catalog {
17301754 dest = dest . name ;
17311755 }
17321756 if ( typeof dest === "string" ) {
1733- resultObj . dest = stringToPDFString ( dest ) ;
1757+ resultObj . dest = stringToPDFString (
1758+ dest ,
1759+ /* keepEscapeSequence = */ true
1760+ ) ;
17341761 } else if ( isValidExplicitDest ( dest ) ) {
17351762 resultObj . dest = dest ;
17361763 }
0 commit comments