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.servicePrincipalCredentialsBuilder()14 .withClientId("PDF_SERVICES_CLIENT_ID")15 .withClientSecret("PDF_SERVICES_CLIENT_SECRET")16 .build();1718 // Create an ExecutionContext using credentials and create a new operation instance.19 ExecutionContext executionContext = ExecutionContext.create(credentials);20 ReorderPagesOperation reorderPagesOperation = ReorderPagesOperation.createNew();2122 // Set operation input from a source file, along with specifying the order of the pages for23 // rearranging the pages in a PDF file.24 FileRef source = FileRef.createFromLocalFile("src/main/resources/reorderPagesInput.pdf");25 PageRanges pageRanges = getPageRangeForReorder();26 reorderPagesOperation.setInput(source);27 reorderPagesOperation.setPagesOrder(pageRanges);2829 // Execute the operation.30 FileRef result = reorderPagesOperation.execute(executionContext);3132 // Save the result to the specified location.33 result.saveAs("output/reorderPagesOutput.pdf");3435 } catch (IOException | ServiceApiException | SdkException | ServiceUsageException e) {36 LOGGER.error("Exception encountered while executing operation", e);37 }38 }3940 private static PageRanges getPageRangeForReorder() {41 // Specify order of the pages for an output document.42 PageRanges pageRanges = new PageRanges();43 // Add pages 3 to 4.44 pageRanges.addRange(3, 4);4546 // Add page 1.47 pageRanges.addSinglePage(1);4849 return pageRanges;50 }51 }
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.ServicePrincipalCredentialsBuilder()19 .WithClientId("PDF_SERVICES_CLIENT_ID")20 .WithClientSecret("PDF_SERVICES_CLIENT_SECRET")21 .Build();2223 // Create an ExecutionContext using credentials.24 ExecutionContext executionContext = ExecutionContext.Create(credentials);2526 // Create a new operation instance27 ReorderPagesOperation reorderPagesOperation = ReorderPagesOperation.CreateNew();2829 // Set operation input from a source file, along with specifying the order of the pages for30 // rearranging the pages in a PDF file.31 FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"reorderPagesInput.pdf");32 reorderPagesOperation.SetInput(sourceFileRef);33 PageRanges pageRanges = GetPageRangeForReorder();34 reorderPagesOperation.SetPagesOrder(pageRanges);3536 // Execute the operation.37 FileRef result = reorderPagesOperation.Execute(executionContext);3839 // Save the result to the specified location.40 result.SaveAs(Directory.GetCurrentDirectory() + "/output/reorderPagesOutput.pdf");41 }42 catch (ServiceUsageException ex)43 {44 log.Error("Exception encountered while executing operation", ex);45 }46 // Catch more errors here . . .47 }4849 private static PageRanges GetPageRangeForReorder()50 {51 // Specify order of the pages for an output document.52 PageRanges pageRanges = new PageRanges();53 // Add pages 3 to 4.54 pageRanges.AddRange(3, 4);5556 // Add page 1.57 pageRanges.AddSinglePage(1);5859 return pageRanges;60 }6162 static void ConfigureLogging()63 {64 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());65 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));66 }67 }68 }
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 .servicePrincipalCredentialsBuilder()23 .withClientId("PDF_SERVICES_CLIENT_ID")24 .withClientSecret("PDF_SERVICES_CLIENT_SECRET")25 .build();2627 // Create an ExecutionContext using credentials and create a new operation instance.28 const executionContext = PDFServicesSdk.ExecutionContext.create(credentials),29 reorderPagesOperation = PDFServicesSdk.ReorderPages.Operation.createNew();3031 // Set operation input from a source file, along with specifying the order of the pages for32 // rearranging the pages in a PDF file.33 const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/reorderPagesInput.pdf');34 const pageRanges = getPageRangeForReorder();35 reorderPagesOperation.setInput(input);36 reorderPagesOperation.setPagesOrder(pageRanges);3738 // Execute the operation and Save the result to the specified location.39 reorderPagesOperation.execute(executionContext)40 .then(result => result.saveAsFile('output/reorderPagesOutput.pdf'))41 .catch(err => {42 if(err instanceof PDFServicesSdk.Error.ServiceApiError43 || err instanceof PDFServicesSdk.Error.ServiceUsageError) {44 console.log('Exception encountered while executing operation', err);45 } else {46 console.log('Exception encountered while executing operation', err);47 }48 });49 } catch (err) {50 console.log('Exception encountered while executing operation', err);51 }
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