Split PDF
Split a PDF document into multiple smaller documents by simply specifying either the number of files, pages per file, or page ranges.
Rest API
See our public API Reference for Split PDF.
Split PDF by number of pages
This operation splits a PDF into multiple smaller documents. Simply use the page count to specify the maximum number of pages of each output file.
Please refer the API usage guide to understand how to use our APIs.
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.splitpdf.SplitPDFByNumberOfPages45 public class SplitPDFByNumberOfPages {67 // Initialize the logger.8 private static final Logger LOGGER = LoggerFactory.getLogger(SplitPDFByNumberOfPages.class);910 public static void main(String[] args) {11 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/splitPDFInput.pdf").toPath())) {12 // Initial setup, create credentials instance13 Credentials credentials = new ServicePrincipalCredentials(14 System.getenv("PDF_SERVICES_CLIENT_ID"),15 System.getenv("PDF_SERVICES_CLIENT_SECRET"));1617 // Creates a PDF Services instance18 PDFServices pdfServices = new PDFServices(credentials);1920 // Creates an asset(s) from source file(s) and upload21 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());2223 // Create parameters for the job24 SplitPDFParams splitPDFParams = new SplitPDFParams();25 // Sets the maximum number of pages each of the output files can have26 splitPDFParams.setPageCount(2);2728 // Creates a new job instance29 SplitPDFJob splitPDFJob = new SplitPDFJob(asset, splitPDFParams);3031 // Submit the job and gets the job result32 String location = pdfServices.submit(splitPDFJob);33 PDFServicesResponse<SplitPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, SplitPDFResult.class);3435 // Get content from the resulting asset(s)36 List<Asset> resultAssets = pdfServicesResponse.getResult().getAssets();3738 Files.createDirectories(Paths.get("output/"));39 int index = 0;40 for (Asset resultAsset : resultAssets) {41 StreamAsset streamAsset = pdfServices.getContent(resultAsset);4243 // Creates an output stream and copy stream asset's content to it44 OutputStream outputStream = Files.newOutputStream(new File("output/SplitPDFByNumberOfPagesOutput_" + index + ".pdf").toPath());45 LOGGER.info("Saving asset at output/SplitPDFByNumberOfPagesOutput_" + index + ".pdf");46 IOUtils.copy(streamAsset.getInputStream(), outputStream);47 outputStream.close();48 index++;49 }50 } catch (IOException| ServiceApiException | SDKException | ServiceUsageException e) {51 LOGGER.error("Exception encountered while executing operation", e);52 }53 }5455 }
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd SplitPDFByNumberOfPages/4// dotnet run SplitPDFByNumberOfPages.csproj56 namespace SplitPDFByNumberOfPages7 {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 SplitPDFOperation splitPDFOperation = SplitPDFOperation.CreateNew();2829 // Set operation input from a source file.30 FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"splitPDFInput.pdf");31 splitPDFOperation.SetInput(sourceFileRef);3233 // Set the maximum number of pages each of the output files can have.34 splitPDFOperation.SetPageCount(2);3536 // Execute the operation.37 List result = splitPDFOperation.Execute(executionContext);3839 // Save the result to the specified location.40 int index = 0;41 foreach (FileRef fileRef in result)42 {43 fileRef.SaveAs(Directory.GetCurrentDirectory() + "/output/SplitPDFByNumberOfPagesOutput_" + index + ".pdf");44 index++;45 }4647 }48 catch (ServiceUsageException ex)49 {50 log.Error("Exception encountered while executing operation", ex);51 }52 // Catch more errors here . . .53 }5455 static void ConfigureLogging()56 {57 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());58 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));59 }60 }61 }
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/splitpdf/split-pdf-by-number-of-pages.js45 const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');67 try {8 // Initial setup, create credentials instance.9 const credentials = PDFServicesSdk.Credentials10 .servicePrincipalCredentialsBuilder()11 .withClientId("PDF_SERVICES_CLIENT_ID")12 .withClientSecret("PDF_SERVICES_CLIENT_SECRET")13 .build();1415 // Create an ExecutionContext using credentials16 const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);1718 // Create a new operation instance.19 const splitPDFOperation = PDFServicesSdk.SplitPDF.Operation.createNew(),20 input = PDFServicesSdk.FileRef.createFromLocalFile(21 'resources/splitPDFInput.pdf',22 PDFServicesSdk.SplitPDF.SupportedSourceFormat.pdf23 );24 // Set operation input from a source file.25 splitPDFOperation.setInput(input);2627 // Set the maximum number of pages each of the output files can have.28 splitPDFOperation.setPageCount(2);2930 // Execute the operation and Save the result to the specified location.31 splitPDFOperation.execute(executionContext)32 .then(result => {33 let saveFilesPromises = [];34 for(let i = 0; i < result.length; i++){35 saveFilesPromises.push(result[i].saveAsFile(`output/SplitPDFByNumberOfPagesOutput_${i}.pdf`));36 }37 return Promise.all(saveFilesPromises);38 })39 .catch(err => {40 if(err instanceof PDFServicesSdk.Error.ServiceApiError41 || err instanceof PDFServicesSdk.Error.ServiceUsageError) {42 console.log('Exception encountered while executing operation', err);43 } else {44 console.log('Exception encountered while executing operation', err);45 }46 });47 } catch (err) {48 console.log('Exception encountered while executing operation', err);49 }50
Copied to your clipboard1// Please refer our Rest API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Split-PDF34curl --location --request POST 'https://pdf-services.adobe.io/operation/splitpdf' \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 "splitoption": {11 "pageCount": 912 }13}'1415// Legacy API can be found here16// https://documentcloud.adobe.com/document-services/index.html#post-splitPDF
Split PDF by page ranges
As an alternative to creating smaller PDFs with a set number of pages, you can split PDFs into multiple smaller documents by specifying page ranges where each page range corresponds to a single output file.
Please refer the API usage guide to understand how to use our APIs.
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.splitpdf.SplitPDFByPageRanges45 public class SplitPDFByPageRanges {67 // Initialize the logger.8 private static final Logger LOGGER = LoggerFactory.getLogger(SplitPDFByPageRanges.class);910 public static void main(String[] args) {11 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/splitPDFInput.pdf").toPath())) {12 // Initial setup, create credentials instance13 Credentials credentials = new ServicePrincipalCredentials(14 System.getenv("PDF_SERVICES_CLIENT_ID"),15 System.getenv("PDF_SERVICES_CLIENT_SECRET"));1617 // Creates a PDF Services instance18 PDFServices pdfServices = new PDFServices(credentials);1920 // Creates an asset(s) from source file(s) and upload21 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());2223 // Specify page ranges to split PDF24 PageRanges pageRanges = getPageRanges();2526 // Create parameters for the job27 SplitPDFParams splitPDFParams = new SplitPDFParams();28 // Set the page ranges where each page range corresponds to a single output file29 splitPDFParams.setPageRanges(pageRanges);3031 // Creates a new job instance32 SplitPDFJob splitPDFJob = new SplitPDFJob(asset, splitPDFParams);3334 // Submit the job and gets the job result35 String location = pdfServices.submit(splitPDFJob);36 PDFServicesResponse<SplitPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, SplitPDFResult.class);3738 // Get content from the resulting asset(s)39 List<Asset> resultAssets = pdfServicesResponse.getResult().getAssets();4041 Files.createDirectories(Paths.get("output/"));42 int index = 0;43 for (Asset resultAsset : resultAssets) {44 StreamAsset streamAsset = pdfServices.getContent(resultAsset);4546 // Creates an output stream and copy stream asset's content to it47 OutputStream outputStream = Files.newOutputStream(new File("output/SplitPDFByPageRangesOutput_" + index + ".pdf").toPath());48 LOGGER.info("Saving asset at output/SplitPDFByPageRangesOutput_" + index + ".pdf");49 IOUtils.copy(streamAsset.getInputStream(), outputStream);50 outputStream.close();51 index++;52 }53 } catch (IOException | ServiceApiException | SDKException | ServiceUsageException e) {54 LOGGER.error("Exception encountered while executing operation", e);55 }56 }5758 private static PageRanges getPageRanges() {59 // Specify page ranges60 PageRanges pageRanges = new PageRanges();61 // Add page 162 pageRanges.addSinglePage(1);6364 // Add pages 3 to 465 pageRanges.addRange(3, 4);66 return pageRanges;67 }6869 }70
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd SplitPDFByPageRanges/4// dotnet run SplitPDFByPageRanges.csproj56 namespace SplitPDFByPageRanges7 {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 SplitPDFOperation splitPDFOperation = SplitPDFOperation.CreateNew();2829 // Set operation input from a source file.30 FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"splitPDFInput.pdf");31 splitPDFOperation.SetInput(sourceFileRef);3233 // Set the page ranges where each page range corresponds to a single output file.34 PageRanges pageRanges = GetPageRanges();35 splitPDFOperation.SetPageRanges(pageRanges);3637 // Execute the operation.38 List result = splitPDFOperation.Execute(executionContext);3940 // Save the result to the specified location.41 int index = 0;42 foreach (FileRef fileRef in result)43 {44 fileRef.SaveAs(Directory.GetCurrentDirectory() + "/output/SplitPDFByPageRangesOutput_" + index + ".pdf");45 index++;46 }4748 }49 catch (ServiceUsageException ex)50 {51 log.Error("Exception encountered while executing operation", ex);52 }53 // Catch more errors here . . .54 }5556 static void ConfigureLogging()57 {58 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());59 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));60 }6162 private static PageRanges GetPageRanges()63 {64 // Specify page ranges.65 PageRanges pageRanges = new PageRanges();66 // Add page 1.67 pageRanges.AddSinglePage(1);6869 // Add pages 3 to 4.70 pageRanges.AddRange(3, 4);71 return pageRanges;72 }73 }74 }
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/splitpdf/split-pdf-by-page-ranges.js45 const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');67 const getPageRanges = () => {8 // Specify pages ranges.9 const pageRanges = new PDFServicesSdk.PageRanges();10 // Add page 1.11 pageRanges.addSinglePage(1);1213 // Add pages 3 to 4.14 pageRanges.addPageRange(3, 4);15 return pageRanges;16 };17 try {18 // Initial setup, create credentials instance.19 const credentials = PDFServicesSdk.Credentials20 .servicePrincipalCredentialsBuilder()21 .withClientId("PDF_SERVICES_CLIENT_ID")22 .withClientSecret("PDF_SERVICES_CLIENT_SECRET")23 .build();2425 // Create an ExecutionContext using credentials26 const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);2728 // Create a new operation instance.29 const splitPDFOperation = PDFServicesSdk.SplitPDF.Operation.createNew(),30 input = PDFServicesSdk.FileRef.createFromLocalFile(31 'resources/splitPDFInput.pdf',32 PDFServicesSdk.SplitPDF.SupportedSourceFormat.pdf33 );34 // Set operation input from a source file.35 splitPDFOperation.setInput(input);3637 // Set the page ranges where each page range corresponds to a single output file.38 const pageRanges = getPageRanges();39 splitPDFOperation.setPageRanges(pageRanges);4041 // Execute the operation and Save the result to the specified location.42 splitPDFOperation.execute(executionContext)43 .then(result => {44 let saveFilesPromises = [];45 for(let i = 0; i < result.length; i++){46 saveFilesPromises.push(result[i].saveAsFile(`output/SplitPDFByPageRangesOutput_${i}.pdf`));47 }48 return Promise.all(saveFilesPromises);49 })50 .catch(err => {51 if(err instanceof PDFServicesSdk.Error.ServiceApiError52 || err instanceof PDFServicesSdk.Error.ServiceUsageError) {53 console.log('Exception encountered while executing operation', err);54 } else {55 console.log('Exception encountered while executing operation', err);56 }57 });58 } catch (err) {59 console.log('Exception encountered while executing operation', err);60 }
Copied to your clipboard1// Please refer our Rest API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Split-PDF34curl --location --request POST 'https://pdf-services.adobe.io/operation/splitpdf' \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 "splitoption": {11 "pageRanges": [12 {13 "start": 2,14 "end": 415 },16 {17 "start": 7,18 "end": 919 }20 ]21 }22}'2324// Legacy API can be found here25// https://documentcloud.adobe.com/document-services/index.html#post-splitPDF
Split PDF into number of files
As an alternative to creating smaller PDFs by specifying a set number of pages or a page range, you can split PDFs by file count. In this case, the operation creates the specified number of files with each containing an identical number of pages (if possible).
Please refer the API usage guide to understand how to use our APIs.
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.splitpdf.SplitPDFIntoNumberOfFiles45 public class SplitPDFIntoNumberOfFiles {67 // Initialize the logger.8 private static final Logger LOGGER = LoggerFactory.getLogger(SplitPDFIntoNumberOfFiles.class);910 public static void main(String[] args) {11 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/splitPDFInput.pdf").toPath())) {12 // Initial setup, create credentials instance13 Credentials credentials = new ServicePrincipalCredentials(14 System.getenv("PDF_SERVICES_CLIENT_ID"),15 System.getenv("PDF_SERVICES_CLIENT_SECRET"));1617 // Creates a PDF Services instance18 PDFServices pdfServices = new PDFServices(credentials);1920 // Creates an asset(s) from source file(s) and upload21 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());2223 // Create parameters for the job24 SplitPDFParams splitPDFParams = new SplitPDFParams();25 // Sets the number of documents to split the input PDF file into26 splitPDFParams.setFileCount(2);2728 // Creates a new job instance29 SplitPDFJob splitPDFJob = new SplitPDFJob(asset, splitPDFParams);3031 // Submit the job and gets the job result32 String location = pdfServices.submit(splitPDFJob);33 PDFServicesResponse<SplitPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, SplitPDFResult.class);3435 // Get content from the resulting asset(s)36 List<Asset> resultAssets = pdfServicesResponse.getResult().getAssets();3738 Files.createDirectories(Paths.get("output/"));39 int index = 0;40 for (Asset resultAsset : resultAssets) {41 StreamAsset streamAsset = pdfServices.getContent(resultAsset);4243 // Creates an output stream and copy stream asset's content to it44 OutputStream outputStream = Files.newOutputStream(new File("output/SplitPDFIntoNumberOfFilesOutput_" + index + ".pdf").toPath());45 LOGGER.info("Saving asset at output/SplitPDFIntoNumberOfFilesOutput_" + index + ".pdf");46 IOUtils.copy(streamAsset.getInputStream(), outputStream);47 outputStream.close();48 index++;49 }50 } catch (IOException | ServiceApiException | SDKException | ServiceUsageException e) {51 LOGGER.error("Exception encountered while executing operation", e);52 }53 }5455 }56
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd SplitPDFIntoNumberOfFiles/4// dotnet run SplitPDFIntoNumberOfFiles.csproj56 namespace SplitPDFIntoNumberOfFiles7 {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 SplitPDFOperation splitPDFOperation = SplitPDFOperation.CreateNew();2829 // Set operation input from a source file.30 FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"splitPDFInput.pdf");31 splitPDFOperation.SetInput(sourceFileRef);3233 // Set the number of documents to split the input PDF file into.34 splitPDFOperation.SetFileCount(2);3536 // Execute the operation.37 List result = splitPDFOperation.Execute(executionContext);3839 // Save the result to the specified location.40 int index = 0;41 foreach (FileRef fileRef in result)42 {43 fileRef.SaveAs(Directory.GetCurrentDirectory() + "/output/SplitPDFIntoNumberOfFilesOutput_" + index + ".pdf");44 index++;45 }4647 }48 catch (ServiceUsageException ex)49 {50 log.Error("Exception encountered while executing operation", ex);51 }52 // Catch more errors here . . .53 }5455 static void ConfigureLogging()56 {57 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());58 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));59 }60 }61 }62
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/splitpdf/split-pdf-into-number-of-files.js45 const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');67 try {8 // Initial setup, create credentials instance.9 const credentials = PDFServicesSdk.Credentials10 .servicePrincipalCredentialsBuilder()11 .withClientId("PDF_SERVICES_CLIENT_ID")12 .withClientSecret("PDF_SERVICES_CLIENT_SECRET")13 .build();1415 // Create an ExecutionContext using credentials16 const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);1718 // Create a new operation instance.19 const splitPDFOperation = PDFServicesSdk.SplitPDF.Operation.createNew(),20 input = PDFServicesSdk.FileRef.createFromLocalFile(21 'resources/splitPDFInput.pdf',22 PDFServicesSdk.SplitPDF.SupportedSourceFormat.pdf23 );24 // Set operation input from a source file.25 splitPDFOperation.setInput(input);2627 // Set the number of documents to split the input PDF file into.28 splitPDFOperation.setFileCount(2);2930 // Execute the operation and Save the result to the specified location.31 splitPDFOperation.execute(executionContext)32 .then(result => {33 let saveFilesPromises = [];34 for(let i = 0; i < result.length; i++){35 saveFilesPromises.push(result[i].saveAsFile(`output/SplitPDFIntoNumberOfFilesOutput_${i}.pdf`));36 }37 return Promise.all(saveFilesPromises);38 })39 .catch(err => {40 if(err instanceof PDFServicesSdk.Error.ServiceApiError41 || err instanceof PDFServicesSdk.Error.ServiceUsageError) {42 console.log('Exception encountered while executing operation', err);43 } else {44 console.log('Exception encountered while executing operation', err);45 }46 });47 } catch (err) {48 console.log('Exception encountered while executing operation', err);49 }
Copied to your clipboard1// Please refer our Rest API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Split-PDF34curl --location --request POST 'https://pdf-services.adobe.io/operation/splitpdf' \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 "splitoption": {11 "fileCount": 312 }13}'1415// Legacy API can be found here16// https://documentcloud.adobe.com/document-services/index.html#post-splitPDF