@@ -61,14 +61,14 @@ import {
6161 RefSetCache ,
6262} from "./primitives.js" ;
6363import { getXfaFontDict , getXfaFontName } from "./xfa_fonts.js" ;
64+ import { NullStream , Stream } from "./stream.js" ;
6465import { BaseStream } from "./base_stream.js" ;
6566import { calculateMD5 } from "./calculate_md5.js" ;
6667import { Catalog } from "./catalog.js" ;
6768import { clearGlobalCaches } from "./cleanup_helper.js" ;
6869import { DatasetReader } from "./dataset_reader.js" ;
6970import { Intersector } from "./intersector.js" ;
7071import { Linearization } from "./parser.js" ;
71- import { NullStream } from "./stream.js" ;
7272import { ObjectLoader } from "./object_loader.js" ;
7373import { OperatorList } from "./operator_list.js" ;
7474import { PartialEvaluator } from "./evaluator.js" ;
@@ -271,9 +271,31 @@ class Page {
271271 const content = await this . pdfManager . ensure ( this , "content" ) ;
272272
273273 if ( content instanceof BaseStream && ! content . isImageStream ) {
274+ if ( content . isAsync ) {
275+ const bytes = await content . asyncGetBytes ( ) ;
276+ if ( bytes ) {
277+ return new Stream ( bytes , 0 , bytes . length , content . dict ) ;
278+ }
279+ }
274280 return content ;
275281 }
276282 if ( Array . isArray ( content ) ) {
283+ const promises = [ ] ;
284+ for ( let i = 0 , ii = content . length ; i < ii ; i ++ ) {
285+ const item = content [ i ] ;
286+ if ( item instanceof BaseStream && item . isAsync ) {
287+ promises . push (
288+ item . asyncGetBytes ( ) . then ( bytes => {
289+ if ( bytes ) {
290+ content [ i ] = new Stream ( bytes , 0 , bytes . length , item . dict ) ;
291+ }
292+ } )
293+ ) ;
294+ }
295+ }
296+ if ( promises . length > 0 ) {
297+ await Promise . all ( promises ) ;
298+ }
277299 return new StreamsSequenceStream (
278300 content ,
279301 this . #onSubStreamError. bind ( this )
0 commit comments