@@ -6253,6 +6253,44 @@ small scripts as well as for`);
62536253
62546254 await loadingTask . destroy ( ) ;
62556255 } ) ;
6256+
6257+ it ( "fills missing pageIndices with the first free slots" , async function ( ) {
6258+ let loadingTask = getDocument (
6259+ buildGetDocumentParams ( "tracemonkey.pdf" )
6260+ ) ;
6261+ let pdfDoc = await loadingTask . promise ;
6262+ const data = await pdfDoc . extractPages ( [
6263+ { document : null , includePages : [ 1 , 3 , 5 ] , pageIndices : [ 1 ] } ,
6264+ ] ) ;
6265+ await loadingTask . destroy ( ) ;
6266+
6267+ loadingTask = getDocument ( data ) ;
6268+ pdfDoc = await loadingTask . promise ;
6269+
6270+ expect ( pdfDoc . numPages ) . toEqual ( 3 ) ;
6271+
6272+ // Page 4 in the original document should occupy the first free slot.
6273+ let pdfPage = await pdfDoc . getPage ( 1 ) ;
6274+ let { items : textItems } = await pdfPage . getTextContent ( ) ;
6275+ expect ( mergeText ( textItems ) . includes ( "3. Trace Trees" ) ) . toBeTrue ( ) ;
6276+
6277+ // Page 2 in the original document keeps its explicit destination slot.
6278+ pdfPage = await pdfDoc . getPage ( 2 ) ;
6279+ ( { items : textItems } = await pdfPage . getTextContent ( ) ) ;
6280+ expect (
6281+ mergeText ( textItems ) . includes ( "2. Overview: Example Tracing Run" )
6282+ ) . toBeTrue ( ) ;
6283+
6284+ // Page 6 in the original document should occupy the remaining free
6285+ // slot.
6286+ pdfPage = await pdfDoc . getPage ( 3 ) ;
6287+ ( { items : textItems } = await pdfPage . getTextContent ( ) ) ;
6288+ expect (
6289+ mergeText ( textItems ) . includes ( "4. Nested Trace Tree Formation" )
6290+ ) . toBeTrue ( ) ;
6291+
6292+ await loadingTask . destroy ( ) ;
6293+ } ) ;
62566294 } ) ;
62576295
62586296 describe ( "AcroForm" , function ( ) {
0 commit comments