@@ -821,48 +821,7 @@ class PDFDocument {
821
821
} ) ;
822
822
}
823
823
824
- get xfaDatasets ( ) {
825
- const acroForm = this . catalog . acroForm ;
826
- if ( ! acroForm ) {
827
- return shadow ( this , "xfaDatasets" , null ) ;
828
- }
829
-
830
- const xfa = acroForm . get ( "XFA" ) ;
831
- if ( xfa instanceof BaseStream && ! xfa . isEmpty ) {
832
- try {
833
- const xdp = stringToUTF8String ( xfa . getString ( ) ) ;
834
- return shadow ( this , "xfaDatasets" , new DatasetReader ( { xdp } ) ) ;
835
- } catch ( _ ) {
836
- warn ( "XFA - Invalid utf-8 string." ) ;
837
- return shadow ( this , "xfaDatasets" , null ) ;
838
- }
839
- }
840
-
841
- if ( ! Array . isArray ( xfa ) || xfa . length === 0 ) {
842
- return null ;
843
- }
844
-
845
- for ( let i = 0 , ii = xfa . length ; i < ii ; i += 2 ) {
846
- if ( xfa [ i ] !== "datasets" ) {
847
- continue ;
848
- }
849
- const data = this . xref . fetchIfRef ( xfa [ i + 1 ] ) ;
850
- if ( ! ( data instanceof BaseStream ) || data . isEmpty ) {
851
- continue ;
852
- }
853
- try {
854
- const datasets = stringToUTF8String ( data . getString ( ) ) ;
855
- return shadow ( this , "xfaDatasets" , new DatasetReader ( { datasets } ) ) ;
856
- } catch ( _ ) {
857
- warn ( "XFA - Invalid utf-8 string." ) ;
858
- return shadow ( this , "xfaDatasets" , null ) ;
859
- }
860
- }
861
-
862
- return shadow ( this , "xfaDatasets" , null ) ;
863
- }
864
-
865
- get xfaData ( ) {
824
+ get _xfaStreams ( ) {
866
825
const acroForm = this . catalog . acroForm ;
867
826
if ( ! acroForm ) {
868
827
return null ;
@@ -880,13 +839,8 @@ class PDFDocument {
880
839
"/xdp:xdp" : "" ,
881
840
} ;
882
841
if ( xfa instanceof BaseStream && ! xfa . isEmpty ) {
883
- try {
884
- entries [ "xdp:xdp" ] = stringToUTF8String ( xfa . getString ( ) ) ;
885
- return entries ;
886
- } catch ( _ ) {
887
- warn ( "XFA - Invalid utf-8 string." ) ;
888
- return null ;
889
- }
842
+ entries [ "xdp:xdp" ] = xfa ;
843
+ return entries ;
890
844
}
891
845
892
846
if ( ! Array . isArray ( xfa ) || xfa . length === 0 ) {
@@ -910,14 +864,51 @@ class PDFDocument {
910
864
if ( ! ( data instanceof BaseStream ) || data . isEmpty ) {
911
865
continue ;
912
866
}
867
+ entries [ name ] = data ;
868
+ }
869
+ return entries ;
870
+ }
871
+
872
+ get xfaDatasets ( ) {
873
+ const streams = this . _xfaStreams ;
874
+ if ( ! streams ) {
875
+ return shadow ( this , "xfaDatasets" , null ) ;
876
+ }
877
+ for ( const key of [ "datasets" , "xdp:xdp" ] ) {
878
+ const stream = streams [ key ] ;
879
+ if ( ! stream ) {
880
+ continue ;
881
+ }
882
+ try {
883
+ const str = stringToUTF8String ( stream . getString ( ) ) ;
884
+ const data = { [ key ] : str } ;
885
+ return shadow ( this , "xfaDatasets" , new DatasetReader ( data ) ) ;
886
+ } catch ( _ ) {
887
+ warn ( "XFA - Invalid utf-8 string." ) ;
888
+ break ;
889
+ }
890
+ }
891
+ return shadow ( this , "xfaDatasets" , null ) ;
892
+ }
893
+
894
+ get xfaData ( ) {
895
+ const streams = this . _xfaStreams ;
896
+ if ( ! streams ) {
897
+ return null ;
898
+ }
899
+ const data = Object . create ( null ) ;
900
+ for ( const [ key , stream ] of Object . entries ( streams ) ) {
901
+ if ( ! stream ) {
902
+ continue ;
903
+ }
913
904
try {
914
- entries [ name ] = stringToUTF8String ( data . getString ( ) ) ;
905
+ data [ key ] = stringToUTF8String ( stream . getString ( ) ) ;
915
906
} catch ( _ ) {
916
907
warn ( "XFA - Invalid utf-8 string." ) ;
917
908
return null ;
918
909
}
919
910
}
920
- return entries ;
911
+ return data ;
921
912
}
922
913
923
914
get xfaFactory ( ) {
0 commit comments