Delete Pages
Delete one or more pages from a document
Rest API
See our public API Reference for Delete Pages
Delete Pages in a PDF
The delete pages operation selectively removes pages from 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.deletepages.DeletePDFPages456 public class DeletePDFPages {78 // Initialize the logger.9 private static final Logger LOGGER = LoggerFactory.getLogger(DeletePDFPages.class);1011 public static void main(String[] args) {12 try {13 // Initial setup, create credentials instance.14 Credentials credentials = Credentials.servicePrincipalCredentialsBuilder()15 .withClientId("PDF_SERVICES_CLIENT_ID")16 .withClientSecret("PDF_SERVICES_CLIENT_SECRET")17 .build();1819 // Create an ExecutionContext using credentials and create a new operation instance.20 ExecutionContext executionContext = ExecutionContext.create(credentials);21 DeletePagesOperation deletePagesOperation = DeletePagesOperation.createNew();2223 // Set operation input from a source file.24 FileRef source = FileRef.createFromLocalFile("src/main/resources/deletePagesInput.pdf");25 deletePagesOperation.setInput(source);2627 // Delete pages of the document (as specified by PageRanges).28 PageRanges pageRangeForDeletion = getPageRangeForDeletion();29 deletePagesOperation.setPageRanges(pageRangeForDeletion);3031 // Execute the operation.32 FileRef result = deletePagesOperation.execute(executionContext);3334 // Save the result to the specified location.35 result.saveAs("output/deletePagesOutput.pdf");3637 } catch (IOException | ServiceApiException | SdkException | ServiceUsageException e) {38 LOGGER.error("Exception encountered while executing operation", e);39 }40 }4142 private static PageRanges getPageRangeForDeletion() {43 // Specify pages for deletion.44 PageRanges pageRangeForDeletion = new PageRanges();45 // Add page 1.46 pageRangeForDeletion.addSinglePage(1);4748 // Add pages 3 to 4.49 pageRangeForDeletion.addRange(3, 4);50 return pageRangeForDeletion;51 }52 }
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd DeletePDFPages/4// dotnet run DeletePDFPages.csproj56 namespace DeletePDFPages7 {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 DeletePagesOperation deletePagesOperation = DeletePagesOperation.CreateNew();2829 // Set operation input from a source file.30 FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"deletePagesInput.pdf");31 deletePagesOperation.SetInput(sourceFileRef);3233 // Delete pages of the document (as specified by PageRanges).34 PageRanges pageRangeForDeletion = GetPageRangeForDeletion();35 deletePagesOperation.SetPageRanges(pageRangeForDeletion);3637 // Execute the operation.38 FileRef result = deletePagesOperation.Execute(executionContext);3940 // Save the result to the specified location.41 result.SaveAs(Directory.GetCurrentDirectory() + "/output/deletePagesOutput.pdf");42 }43 catch (ServiceUsageException ex)44 {45 log.Error("Exception encountered while executing operation", ex);46 }47 // Catch more errors here . . .48 }4950 private static PageRanges GetPageRangeForDeletion()51 {52 // Specify pages for deletion.53 PageRanges pageRangeForDeletion = new PageRanges();54 // Add page 1.55 pageRangeForDeletion.AddSinglePage(1);5657 // Add pages 3 to 4.58 pageRangeForDeletion.AddRange(3, 4);59 return pageRangeForDeletion;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/replacepages/replace-pdf-pages.js45 const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');67 const getPageRangesForDeletion = () => {8 // Specify pages for deletion.9 const pageRangesForDeletion = new PDFServicesSdk.PageRanges();10 // Add page 1.11 pageRangesForDeletion.addSinglePage(1);1213 // Add pages 3 to 4.14 pageRangesForDeletion.addPageRange(3, 4);15 return pageRangesForDeletion;16 };1718 try {19 // Initial setup, create credentials instance.20 const credentials = PDFServicesSdk.Credentials21 .servicePrincipalCredentialsBuilder()22 .withClientId("PDF_SERVICES_CLIENT_ID")23 .withClientSecret("PDF_SERVICES_CLIENT_SECRET")24 .build();2526 // Create an ExecutionContext using credentials and create a new operation instance.27 const executionContext = PDFServicesSdk.ExecutionContext.create(credentials),28 deletePagesOperation = PDFServicesSdk.DeletePages.Operation.createNew();2930 // Set operation input from a source file.31 const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/deletePagesInput.pdf');32 deletePagesOperation.setInput(input);3334 // Delete pages of the document (as specified by PageRanges).35 const pageRangesForDeletion = getPageRangesForDeletion();36 deletePagesOperation.setPageRanges(pageRangesForDeletion);3738 // Execute the operation and Save the result to the specified location.39 deletePagesOperation.execute(executionContext)40 .then(result => result.saveAsFile('output/deletePagesOutput.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/Page-Manipulation34curl --location --request POST 'https://pdf-services.adobe.io/operation/pagemanipulation' \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 "assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718",10 "pageActions": [11 {12 "delete": {13 "pageRanges": [14 {15 "start": 1,16 "end": 217 }18 ]19 }20 }21 ]22}'2324// Legacy API can be found here25// https://documentcloud.adobe.com/document-services/index.html#post-pageManipulation