Move or Copy PDF Pages Using JavaScript
To move or copy pages, you can use our page editor operations.
Using movePages
moves the pages specified in the pageIndexes
array before or after the specified page index:
instance.applyOperations([ { type: "movePages", pageIndexes: [0, 4], // Move pages 0 and 4. beforePageIndex: 7 // The specified pages will be moved after page 7. } ]);
Using duplicatePages
duplicates the pages specified in the pageIndexes
array. Each duplicated page will be inserted after the page being duplicated:
instance.applyOperations([ { type: "duplicatePages", pageIndexes: [0, 4] // Duplicate pages 0 and 4, and insert each duplicate after the original page. } ]);
After this operation is complete, call exportPDF
to get a buffer containing the data for the final PDF.
If you need to apply this operation and export in one step, you can provide the same argument you provide to applyOperations
to exportPDFWithOperations
to get a buffer containing the data for the final PDF.