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.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 InsertPagesOperation insertPagesOperation = InsertPagesOperation.createNew();2021 // Set operation base input from a source file.22 FileRef baseSourceFile = FileRef.createFromLocalFile("src/main/resources/baseInput.pdf");23 insertPagesOperation.setBaseInput(baseSourceFile);2425 // Create a FileRef instance using a local file.26 FileRef firstFileToInsert = FileRef.createFromLocalFile("src/main/resources/firstFileToInsertInput.pdf");27 PageRanges pageRanges = getPageRangeForFirstFile();2829 // Adds the pages (specified by the page ranges) of the input PDF file to be inserted at30 // the specified page of the base PDF file.31 insertPagesOperation.addPagesToInsertAt(firstFileToInsert, pageRanges, 2);3233 // Create a FileRef instance using a local file.34 FileRef secondFileToInsert = FileRef.createFromLocalFile("src/main/resources/secondFileToInsertInput.pdf");3536 // Adds all the pages of the input PDF file to be inserted at the specified page of the37 // base PDF file.38 insertPagesOperation.addPagesToInsertAt(secondFileToInsert, 3);3940 // Execute the operation.41 FileRef result = insertPagesOperation.execute(executionContext);4243 // Save the result to the specified location.44 result.saveAs("output/insertPagesOutput.pdf");4546 } catch (IOException | ServiceApiException | SdkException | ServiceUsageException e) {47 LOGGER.error("Exception encountered while executing operation", e);48 }49 }5051 private static PageRanges getPageRangeForFirstFile() {52 // Specify which pages of the first file are to be inserted in the base file.53 PageRanges pageRanges = new PageRanges();54 // Add pages 1 to 3.55 pageRanges.addRange(1, 3);5657 // Add page 4.58 pageRanges.addSinglePage(4);5960 return pageRanges;61 }62 }
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.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 InsertPagesOperation insertPagesOperation = InsertPagesOperation.CreateNew();2728 // Set operation base input from a source file.29 FileRef baseSourceFile = FileRef.CreateFromLocalFile(@"baseInput.pdf");30 insertPagesOperation.SetBaseInput(baseSourceFile);3132 // Create a FileRef instance using a local file.33 FileRef firstFileToInsert = FileRef.CreateFromLocalFile(@"firstFileToInsertInput.pdf");34 PageRanges pageRanges = GetPageRangeForFirstFile();3536 // Adds the pages (specified by the page ranges) of the input PDF file to be inserted at37 // the specified page of the base PDF file.38 insertPagesOperation.AddPagesToInsertAt(firstFileToInsert, pageRanges, 2);3940 // Create a FileRef instance using a local file.41 FileRef secondFileToInsert = FileRef.CreateFromLocalFile(@"secondFileToInsertInput.pdf");4243 // Adds all the pages of the input PDF file to be inserted at the specified page of the44 // base PDF file.45 insertPagesOperation.AddPagesToInsertAt(secondFileToInsert, 3);4647 // Execute the operation.48 FileRef result = insertPagesOperation.Execute(executionContext);4950 // Save the result to the specified location.51 result.SaveAs(Directory.GetCurrentDirectory() + "/output/insertPagesOutput.pdf");52 }53 catch (ServiceUsageException ex)54 {55 log.Error("Exception encountered while executing operation", ex);56 // Catch more errors here . . .57 }5859 private static PageRanges GetPageRangeForFirstFile()60 {61 // Specify which pages of the first file are to be inserted in the base file.62 PageRanges pageRanges = new PageRanges();63 // Add pages 1 to 3.64 pageRanges.AddRange(1, 3);6566 // Add page 4.67 pageRanges.AddSinglePage(4);6869 return pageRanges;70 }7172 static void ConfigureLogging()73 {74 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());75 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));76 }77 }78 }
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 .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 insertPagesOperation = PDFServicesSdk.InsertPages.Operation.createNew();2930 // Set operation base input from a source file.31 const baseInputFile = PDFServicesSdk.FileRef.createFromLocalFile('resources/baseInput.pdf');32 insertPagesOperation.setBaseInput(baseInputFile);3334 // Create a FileRef instance using a local file.35 const firstFileToInsert = PDFServicesSdk.FileRef.createFromLocalFile('resources/firstFileToInsertInput.pdf'),36 pageRanges = getPageRangesForFirstFile();3738 // Adds the pages (specified by the page ranges) of the input PDF file to be inserted at39 // the specified page of the base PDF file.40 insertPagesOperation.addPagesToInsertAt(2, firstFileToInsert, pageRanges);4142 // Create a FileRef instance using a local file.43 const secondFileToInsert = PDFServicesSdk.FileRef.createFromLocalFile('resources/secondFileToInsertInput.pdf');4445 // Adds all the pages of the input PDF file to be inserted at the specified page of the46 // base PDF file.47 insertPagesOperation.addPagesToInsertAt(3, secondFileToInsert);4849 // Execute the operation and Save the result to the specified location.50 insertPagesOperation.execute(executionContext)51 .then(result => result.saveAsFile('output/insertPagesOutput.pdf'))52 .catch(err => {53 if (err instanceof PDFServicesSdk.Error.ServiceApiError54 || err instanceof PDFServicesSdk.Error.ServiceUsageError) {55 console.log('Exception encountered while executing operation', err);56 } else {57 console.log('Exception encountered while executing operation', err);58 }59 });60 } catch (err) {61 console.log('Exception encountered while executing operation', err);62 }
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