File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1739,36 +1739,26 @@ class PDFPageProxy {
17391739 * @returns {Promise<TextContent> } A promise that is resolved with a
17401740 * {@link TextContent} object that represents the page's text content.
17411741 */
1742- getTextContent ( params = { } ) {
1742+ async getTextContent ( params = { } ) {
17431743 if ( this . _transport . _htmlForXfa ) {
17441744 // TODO: We need to revisit this once the XFA foreground patch lands and
17451745 // only do this for non-foreground XFA.
17461746 return this . getXfa ( ) . then ( xfa => XfaText . textContent ( xfa ) ) ;
17471747 }
17481748 const readableStream = this . streamTextContent ( params ) ;
17491749
1750- return new Promise ( function ( resolve , reject ) {
1751- function pump ( ) {
1752- reader . read ( ) . then ( function ( { value, done } ) {
1753- if ( done ) {
1754- resolve ( textContent ) ;
1755- return ;
1756- }
1757- textContent . lang ??= value . lang ;
1758- Object . assign ( textContent . styles , value . styles ) ;
1759- textContent . items . push ( ...value . items ) ;
1760- pump ( ) ;
1761- } , reject ) ;
1762- }
1750+ const textContent = {
1751+ items : [ ] ,
1752+ styles : Object . create ( null ) ,
1753+ lang : null ,
1754+ } ;
17631755
1764- const reader = readableStream . getReader ( ) ;
1765- const textContent = {
1766- items : [ ] ,
1767- styles : Object . create ( null ) ,
1768- lang : null ,
1769- } ;
1770- pump ( ) ;
1771- } ) ;
1756+ for await ( const value of readableStream ) {
1757+ textContent . lang ??= value . lang ;
1758+ Object . assign ( textContent . styles , value . styles ) ;
1759+ textContent . items . push ( ...value . items ) ;
1760+ }
1761+ return textContent ;
17721762 }
17731763
17741764 /**
You can’t perform that action at this time.
0 commit comments