@@ -249,7 +249,8 @@ class PDFEditor {
249249 obj = obj . slice ( ) ;
250250 }
251251 for ( let i = 0 , ii = obj . length ; i < ii ; i ++ ) {
252- const postponedActions = postponedRefCopies . get ( obj [ i ] ) ;
252+ const postponedActions =
253+ obj [ i ] instanceof Ref && postponedRefCopies . get ( obj [ i ] ) ;
253254 if ( postponedActions ) {
254255 // The object is a reference that needs to be copied later.
255256 postponedActions . push ( ref => ( obj [ i ] = ref ) ) ;
@@ -277,7 +278,8 @@ class PDFEditor {
277278 }
278279 if ( dict ) {
279280 for ( const [ key , rawObj ] of dict . getRawEntries ( ) ) {
280- const postponedActions = postponedRefCopies . get ( rawObj ) ;
281+ const postponedActions =
282+ rawObj instanceof Ref && postponedRefCopies . get ( rawObj ) ;
281283 if ( postponedActions ) {
282284 // The object is a reference that needs to be copied later.
283285 postponedActions . push ( ref => dict . set ( key , ref ) ) ;
@@ -1083,7 +1085,7 @@ class PDFEditor {
10831085
10841086 // Fix the ID tree.
10851087 for ( const [ id , nodeRef ] of idTree || [ ] ) {
1086- const newNodeRef = oldRefMapping . get ( nodeRef ) ;
1088+ const newNodeRef = nodeRef instanceof Ref && oldRefMapping . get ( nodeRef ) ;
10871089 const newId = dedupIDs . get ( id ) || id ;
10881090 if ( newNodeRef ) {
10891091 newIdTree . set ( newId , newNodeRef ) ;
@@ -1137,7 +1139,7 @@ class PDFEditor {
11371139 const newDestinations = ( documentData . destinations = new Map ( ) ) ;
11381140 for ( const [ key , dest ] of Object . entries ( destinations ) ) {
11391141 const pageRef = dest [ 0 ] ;
1140- const pageData = pagesMap . get ( pageRef ) ;
1142+ const pageData = pageRef instanceof Ref && pagesMap . get ( pageRef ) ;
11411143 if ( ! pageData ) {
11421144 continue ;
11431145 }
@@ -1537,7 +1539,7 @@ class PDFEditor {
15371539 }
15381540 const { oldRefMapping } = documentData ;
15391541 for ( const coRef of co ) {
1540- const newCoRef = oldRefMapping . get ( coRef ) ;
1542+ const newCoRef = coRef instanceof Ref && oldRefMapping . get ( coRef ) ;
15411543 if ( newCoRef ) {
15421544 calculationOrder . push ( newCoRef ) ;
15431545 }
0 commit comments