Insert Pages
Insert one or more pages into an existing document
Rest API
See our public API Reference for Insert Pages
Insert Pages in PDF
The insert operation inserts additional pages from different PDFs into an existing PDF.
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.insertpages.InsertPDFPages45 public class InsertPDFPages {67 // Initialize the logger.8 private static final Logger LOGGER = LoggerFactory.getLogger(InsertPDFPages.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 InsertPagesOperation insertPagesOperation = InsertPagesOperation.createNew();2122 // Set operation base input from a source file.23 FileRef baseSourceFile = FileRef.createFromLocalFile("src/main/resources/baseInput.pdf");24 insertPagesOperation.setBaseInput(baseSourceFile);2526 // Create a FileRef instance using a local file.27 FileRef firstFileToInsert = FileRef.createFromLocalFile("src/main/resources/firstFileToInsertInput.pdf");28 PageRanges pageRanges = getPageRangeForFirstFile();2930 // Adds the pages (specified by the page ranges) of the input PDF file to be inserted at31 // the specified page of the base PDF file.32 insertPagesOperation.addPagesToInsertAt(firstFileToInsert, pageRanges, 2);3334 // Create a FileRef instance using a local file.35 FileRef secondFileToInsert = FileRef.createFromLocalFile("src/main/resources/secondFileToInsertInput.pdf");3637 // Adds all the pages of the input PDF file to be inserted at the specified page of the38 // base PDF file.39 insertPagesOperation.addPagesToInsertAt(secondFileToInsert, 3);4041 // Execute the operation.42 FileRef result = insertPagesOperation.execute(executionContext);4344 // Save the result to the specified location.45 result.saveAs("output/insertPagesOutput.pdf");4647 } catch (IOException | ServiceApiException | SdkException | ServiceUsageException e) {48 LOGGER.error("Exception encountered while executing operation", e);49 }50 }5152 private static PageRanges getPageRangeForFirstFile() {53 // Specify which pages of the first file are to be inserted in the base file.54 PageRanges pageRanges = new PageRanges();55 // Add pages 1 to 3.56 pageRanges.addRange(1, 3);5758 // Add page 4.59 pageRanges.addSinglePage(4);6061 return pageRanges;62 }63 }
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd InsertPDFPages/4// dotnet run InsertPDFPages.csproj56 namespace InsertPDFPages7 {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 InsertPagesOperation insertPagesOperation = InsertPagesOperation.CreateNew();2829 // Set operation base input from a source file.30 FileRef baseSourceFile = FileRef.CreateFromLocalFile(@"baseInput.pdf");31 insertPagesOperation.SetBaseInput(baseSourceFile);3233 // Create a FileRef instance using a local file.34 FileRef firstFileToInsert = FileRef.CreateFromLocalFile(@"firstFileToInsertInput.pdf");35 PageRanges pageRanges = GetPageRangeForFirstFile();3637 // Adds the pages (specified by the page ranges) of the input PDF file to be inserted at38 // the specified page of the base PDF file.39 insertPagesOperation.AddPagesToInsertAt(firstFileToInsert, pageRanges, 2);4041 // Create a FileRef instance using a local file.42 FileRef secondFileToInsert = FileRef.CreateFromLocalFile(@"secondFileToInsertInput.pdf");4344 // Adds all the pages of the input PDF file to be inserted at the specified page of the45 // base PDF file.46 insertPagesOperation.AddPagesToInsertAt(secondFileToInsert, 3);4748 // Execute the operation.49 FileRef result = insertPagesOperation.Execute(executionContext);5051 // Save the result to the specified location.52 result.SaveAs(Directory.GetCurrentDirectory() + "/output/insertPagesOutput.pdf");53 }54 catch (ServiceUsageException ex)55 {56 log.Error("Exception encountered while executing operation", ex);57 // Catch more errors here . . .58 }5960 private static PageRanges GetPageRangeForFirstFile()61 {62 // Specify which pages of the first file are to be inserted in the base file.63 PageRanges pageRanges = new PageRanges();64 // Add pages 1 to 3.65 pageRanges.AddRange(1, 3);6667 // Add page 4.68 pageRanges.AddSinglePage(4);6970 return pageRanges;71 }7273 static void ConfigureLogging()74 {75 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());76 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));77 }78 }79 }
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/insertpages/insert-pdf-pages.js45 const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');67 const getPageRangesForFirstFile = () => {8 // Specify which pages of the first file are to be inserted in the base file.9 const pageRangesForFirstFile = new PDFServicesSdk.PageRanges();10 // Add pages 1 to 3.11 pageRangesForFirstFile.addPageRange(1, 3);1213 // Add page 4.14 pageRangesForFirstFile.addSinglePage(4);1516 return pageRangesForFirstFile;17 };1819 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 insertPagesOperation = PDFServicesSdk.InsertPages.Operation.createNew();3031 // Set operation base input from a source file.32 const baseInputFile = PDFServicesSdk.FileRef.createFromLocalFile('resources/baseInput.pdf');33 insertPagesOperation.setBaseInput(baseInputFile);3435 // Create a FileRef instance using a local file.36 const firstFileToInsert = PDFServicesSdk.FileRef.createFromLocalFile('resources/firstFileToInsertInput.pdf'),37 pageRanges = getPageRangesForFirstFile();3839 // Adds the pages (specified by the page ranges) of the input PDF file to be inserted at40 // the specified page of the base PDF file.41 insertPagesOperation.addPagesToInsertAt(2, firstFileToInsert, pageRanges);4243 // Create a FileRef instance using a local file.44 const secondFileToInsert = PDFServicesSdk.FileRef.createFromLocalFile('resources/secondFileToInsertInput.pdf');4546 // Adds all the pages of the input PDF file to be inserted at the specified page of the47 // base PDF file.48 insertPagesOperation.addPagesToInsertAt(3, secondFileToInsert);4950 // Execute the operation and Save the result to the specified location.51 insertPagesOperation.execute(executionContext)52 .then(result => result.saveAsFile('output/insertPagesOutput.pdf'))53 .catch(err => {54 if (err instanceof PDFServicesSdk.Error.ServiceApiError55 || err instanceof PDFServicesSdk.Error.ServiceUsageError) {56 console.log('Exception encountered while executing operation', err);57 } else {58 console.log('Exception encountered while executing operation', err);59 }60 });61 } catch (err) {62 console.log('Exception encountered while executing operation', err);63 }
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": 1,15 "end": 116 }17 ]18 },19 {20 "assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718",21 "pageRanges": [22 {23 "start": 424 }25 ]26 },27 {28 "assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718",29 "pageRanges": [30 {31 "start": 132 }33 ]34 },35 {36 "assetID": "urn:aaid:AS:UE1:23c30ee0-2e4d-46d6-87f2-087832fca718",37 "pageRanges": [38 {39 "start": 240 }41 ]42 }43 ]44}'4546// Legacy API can be found here47// https://documentcloud.adobe.com/document-services/index.html#post-combinePDF