Reorder Pages
Reorder the pages of a PDF file to reorganize.
Rest API
See our public API Reference for Reorder Pages
Reorder Pages in PDF
The reorder pages operation moves pages from one location to another in a PDF file.
Please refer the API usage guide to understand how to use our APIs.
Java
.NET
Node JS
Rest API
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples2// Run the sample:3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.reorderpages.ReorderPDFPages45 public class ReorderPDFPages {67 // Initialize the logger.8 private static final Logger LOGGER = LoggerFactory.getLogger(ReorderPDFPages.class);910 public static void main(String[] args) {11 try {12 // Initial setup, create credentials instance.13 Credentials credentials = Credentials.serviceAccountCredentialsBuilder()14 .fromFile("pdfservices-api-credentials.json")15 .build();1617 // Create an ExecutionContext using credentials and create a new operation instance.18 ExecutionContext executionContext = ExecutionContext.create(credentials);19 ReorderPagesOperation reorderPagesOperation = ReorderPagesOperation.createNew();2021 // Set operation input from a source file, along with specifying the order of the pages for22 // rearranging the pages in a PDF file.23 FileRef source = FileRef.createFromLocalFile("src/main/resources/reorderPagesInput.pdf");24 PageRanges pageRanges = getPageRangeForReorder();25 reorderPagesOperation.setInput(source);26 reorderPagesOperation.setPagesOrder(pageRanges);2728 // Execute the operation.29 FileRef result = reorderPagesOperation.execute(executionContext);3031 // Save the result to the specified location.32 result.saveAs("output/reorderPagesOutput.pdf");3334 } catch (IOException | ServiceApiException | SdkException | ServiceUsageException e) {35 LOGGER.error("Exception encountered while executing operation", e);36 }37 }3839 private static PageRanges getPageRangeForReorder() {40 // Specify order of the pages for an output document.41 PageRanges pageRanges = new PageRanges();42 // Add pages 3 to 4.43 pageRanges.addRange(3, 4);4445 // Add page 1.46 pageRanges.addSinglePage(1);4748 return pageRanges;49 }50 }
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd ReorderPages/4// dotnet run ReorderPDFPages.csproj56 namespace ReorderPDFPages7 {8 class Program9 {10 private static readonly ILog log = LogManager.GetLogger(typeof(Program));11 static void Main()12 {13 // Configure the logging14 ConfigureLogging();15 try16 {17 // Initial setup, create credentials instance.18 Credentials credentials = Credentials.ServiceAccountCredentialsBuilder()19 .FromFile(Directory.GetCurrentDirectory() + "/pdfservices-api-credentials.json")20 .Build();2122 // Create an ExecutionContext using credentials.23 ExecutionContext executionContext = ExecutionContext.Create(credentials);2425 // Create a new operation instance26 ReorderPagesOperation reorderPagesOperation = ReorderPagesOperation.CreateNew();2728 // Set operation input from a source file, along with specifying the order of the pages for29 // rearranging the pages in a PDF file.30 FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"reorderPagesInput.pdf");31 reorderPagesOperation.SetInput(sourceFileRef);32 PageRanges pageRanges = GetPageRangeForReorder();33 reorderPagesOperation.SetPagesOrder(pageRanges);3435 // Execute the operation.36 FileRef result = reorderPagesOperation.Execute(executionContext);3738 // Save the result to the specified location.39 result.SaveAs(Directory.GetCurrentDirectory() + "/output/reorderPagesOutput.pdf");40 }41 catch (ServiceUsageException ex)42 {43 log.Error("Exception encountered while executing operation", ex);44 }45 // Catch more errors here . . .46 }4748 private static PageRanges GetPageRangeForReorder()49 {50 // Specify order of the pages for an output document.51 PageRanges pageRanges = new PageRanges();52 // Add pages 3 to 4.53 pageRanges.AddRange(3, 4);5455 // Add page 1.56 pageRanges.AddSinglePage(1);5758 return pageRanges;59 }6061 static void ConfigureLogging()62 {63 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());64 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));65 }66 }67 }
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/reorderpages/reorder-pdf-pages.js45 const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');67 const getPageRangeForReorder = () => {8 // Specify order of the pages for an output document.9 const pageRanges = new PDFServicesSdk.PageRanges();1011 // Add pages 3 to 4.12 pageRanges.addPageRange(3, 4);1314 // Add page 1.15 pageRanges.addSinglePage(1);1617 return pageRanges;18 };19 try {20 // Initial setup, create credentials instance.21 const credentials = PDFServicesSdk.Credentials22 .serviceAccountCredentialsBuilder()23 .fromFile("pdfservices-api-credentials.json")24 .build();2526 // Create an ExecutionContext using credentials and create a new operation instance.27 const executionContext = PDFServicesSdk.ExecutionContext.create(credentials),28 reorderPagesOperation = PDFServicesSdk.ReorderPages.Operation.createNew();2930 // Set operation input from a source file, along with specifying the order of the pages for31 // rearranging the pages in a PDF file.32 const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/reorderPagesInput.pdf');33 const pageRanges = getPageRangeForReorder();34 reorderPagesOperation.setInput(input);35 reorderPagesOperation.setPagesOrder(pageRanges);3637 // Execute the operation and Save the result to the specified location.38 reorderPagesOperation.execute(executionContext)39 .then(result => result.saveAsFile('output/reorderPagesOutput.pdf'))40 .catch(err => {41 if(err instanceof PDFServicesSdk.Error.ServiceApiError42 || err instanceof PDFServicesSdk.Error.ServiceUsageError) {43 console.log('Exception encountered while executing operation', err);44 } else {45 console.log('Exception encountered while executing operation', err);46 }47 });48 } catch (err) {49 console.log('Exception encountered while executing operation', err);50 }
Copied to your clipboard1// Please refer our Rest API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Combine-PDF34curl --location --request POST 'https://pdf-services.adobe.io/operation/combinepdf' \5--header 'x-api-key: {{Placeholder for client_id}}' \6--header 'Content-Type: application/json' \7--header 'Authorization: Bearer {{Placeholder for token}}' \8--data-raw '{9 "assets": [10 {11 "assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718",12 "pageRanges": [13 {14 "start": 3,15 "end": 316 },17 {18 "start": 1,19 "end": 120 },21 {22 "start": 4,23 "end": 424 }25 ]26 }27 ]28}'2930// Legacy API can be found here31// https://documentcloud.adobe.com/document-services/index.html#post-combinePDF