How Tos

The samples and documentation here should get you quickly up and running with the DC Services SDK. These code examples illustrate how to perform PDF actions using the SDK, including:

  • Creating a PDF from multiple formats, including HTML, Microsoft Office documents, and text files

  • Exporting a PDF to other formats or an image

  • Combining entire PDFs or specified page ranges

Runtime in-memory authentication

The SDK supports providing the authentication credentials at runtime. Doing so allows fetching the credentials from a secret server during runtime instead of storing them in a file. Please refer the following samples for details.

Create a PDF

Use the sample below to create PDFs from Microsoft Office documents (Word, Excel and PowerPoint) and other supported file formats. While the example shows .docx file conversion, the SDK supports the following formats:

  • Microsoft Word (DOC, DOCX)

  • Microsoft PowerPoint (PPT, PPTX)

  • Microsoft Excel (XLS, XLSX)

  • Text (TXT, RTF)

  • Image (BMP, JPEG, GIF, TIFF, PNG)

Run the sample:
mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.platform.operation.samples.createpdf.CreatePDFFromDOCX
Get the samples from https://www.adobe.com/go/dcservicessdk_java_samples
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adobe.platform.operation.ClientContext;
import com.adobe.platform.operation.exception.SdkException;
import com.adobe.platform.operation.exception.ServiceApiException;
import com.adobe.platform.operation.io.FileRef;
import com.adobe.platform.operation.pdfops.CreatePDFOperation;

public class CreatePDFFromDOCX {

   // Initialize the logger.
   private static final Logger LOGGER = LoggerFactory.getLogger(CreatePDFFromDOCX.class);

   public static void main(String[] args) {

       try {

           // Initial setup, create a ClientContext using a config file and a new operation instance.
           ClientContext clientContext = ClientContext.createFromFile("dc-services-sdk-config.json");
           CreatePDFOperation createPdfOperation = CreatePDFOperation.createNew();

           // Set operation input from a source file.
           FileRef source = FileRef.createFromLocalFile("src/main/resources/createPDFInput.docx");
           createPdfOperation.setInput(source);

           // Execute the operation.
           FileRef result = createPdfOperation.execute(clientContext);

           // Save the result to the specified location.
           result.saveAs("output/createPDFFromDOCX.pdf");

       } catch (ServiceApiException | IOException | SdkException ex) {
           LOGGER.error("Exception encountered while executing operation", ex);
       }
   }
}
     
Run the sample:
cd CreatePDFFromDocx/
dotnet run CreatePDFFromDocx.csproj
// Get the samples from https://www.adobe.com/go/dcservicessdk_net_samples
using System;
using System.IO;
using log4net.Repository;
using log4net.Config;
using log4net;
using System.Reflection;
using Adobe.DocumentCloud.Services;
using Adobe.DocumentCloud.Services.pdfops;
using Adobe.DocumentCloud.Services.io;
using Adobe.DocumentCloud.Services.exception;

namespace CreatePDFFromDocx
{
 class Program
 {
  private static readonly ILog log = LogManager.GetLogger(typeof(Program));
  static void Main()
  {
   //Configure the logging
   ConfigureLogging();
   try
   {
    // Initial setup, create a ClientContext and a new operation instance.
    ClientContext clientContext = ClientContext.CreateFromFile(Directory.GetCurrentDirectory() + "/dc-services-sdk-config.json");
    CreatePDFOperation createPdfOperation = CreatePDFOperation.CreateNew();

    // Set operation input from a source file.
    FileRef source = FileRef.CreateFromLocalFile(@"createPdfInput.docx");
    createPdfOperation.SetInput(source);

    // Execute the operation.
    FileRef result = createPdfOperation.Execute(clientContext);

    // Save the result to the specified location.
    result.SaveAs(Directory.GetCurrentDirectory() + "/output/createPdfOutput.pdf");
   }
   catch (ServiceApiException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch (SDKException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch (IOException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch (Exception ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }

  }

  static void ConfigureLogging()
  {
   ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
   XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
  }
 }
    
Run the sample:
node src/createpdf/create-pdf-from-docx.js
 const DCServicesSdk = require('@adobe/dc-services-node-sdk');

 try {
   // Initial setup, create a ClientContext using a config file, and a new operation instance.
   const clientContext = DCServicesSdk.ClientContext.createFromFile('dc-services-sdk-config.json'),
     createPdfOperation = DCServicesSdk.CreatePDF.Operation.createNew();

   // Set operation input from a source file.
   const input = DCServicesSdk.FileRef.createFromLocalFile('resources/createPDFInput.docx');
   createPdfOperation.setInput(input);

   // Execute the operation and Save the result to the specified location.
   createPdfOperation.execute(clientContext)
     .then(result => result.saveAsFile('output/createPDFFromDOCX.pdf'))
     .catch(err => console.log('Exception encountered while executing operation', err));
 } catch (err) {
   console.log('Exception encountered while executing operation', err);
 }

Create a PDF from local HTML

The sample below creates a PDF file from a local HTML file. Since HTML/web pages typically contain external assets, the input file must be a zip file containing an index.html at the top level of the archive as well as any dependencies such as images, css files, and so on.

Run the sample:
mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.platform.operation.samples.createpdf.CreatePDFFromHTML
// Get the samples from https://www.adobe.com/go/dcservicessdk_java_samples
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adobe.platform.operation.ClientContext;
import com.adobe.platform.operation.exception.SdkException;
import com.adobe.platform.operation.exception.ServiceApiException;
import com.adobe.platform.operation.io.FileRef;
import com.adobe.platform.operation.pdfops.CreatePDFOperation;
import com.adobe.platform.operation.pdfops.options.createpdf.CreatePDFOptions;
import com.adobe.platform.operation.pdfops.options.createpdf.PageLayout;

public class CreatePDFFromHTML {

   // Initialize the logger.
   private static final Logger LOGGER = LoggerFactory.getLogger(CreatePDFFromHTML.class);

   public static void main(String[] args) {

       try {

           // Initial setup, create a ClientContext using a config file, and a new operation instance.
           ClientContext clientContext = ClientContext.createFromFile("dc-services-sdk-config.json");
           CreatePDFOperation htmlToPDFOperation = CreatePDFOperation.createNew();

           // Set operation input from a source file.
           FileRef source = FileRef.createFromLocalFile("src/main/resources/createPdfFromHtmlInput.zip");
           htmlToPDFOperation.setInput(source);

           // Provide any custom configuration options for the operation.
           setCustomOptions(htmlToPDFOperation);

           // Execute the operation.
           FileRef result = htmlToPDFOperation.execute(clientContext);

           // Save the result to the specified location.
           result.saveAs("output/createPdfFromHtmlOutput.pdf");

       } catch (ServiceApiException | IOException | SdkException ex) {
           LOGGER.error("Exception encountered while executing operation", ex);
       }
   }

   private static void setCustomOptions(CreatePDFOperation htmlToPDFOperation) {
       // Define the page layout, in this case an 8 x 11.5 inch page (effectively portrait orientation).
       PageLayout pageLayout = new PageLayout();
       pageLayout.setPageSize(8, 11.5);
       // Set the desired HTML-to-PDF conversion options.
       CreatePDFOptions htmlToPdfOptions = CreatePDFOptions.htmlOptionsBuilder()
               .includeHeaderFooter(true)
               .withPageLayout(pageLayout)
               .build();
       htmlToPDFOperation.setOptions(htmlToPdfOptions);
   }
}
     
Run the sample:
cd CreatePDFFromHtml/
dotnet run CreatePDFFromHtml.csproj
// Get the samples from https://www.adobe.com/go/dcservicessdk_net_samples
using System;
using System.IO;
using log4net.Repository;
using log4net;
using log4net.Config;
using System.Reflection;
using Adobe.DocumentCloud.Services;
using Adobe.DocumentCloud.Services.pdfops;
using Adobe.DocumentCloud.Services.io;
using Adobe.DocumentCloud.Services.exception;
using Adobe.DocumentCloud.Services.options.createpdf;

namespace CreatePDFFromHtml
{
 class Program
 {
  private static readonly ILog log = LogManager.GetLogger(typeof(Program));
  static void Main()
  {
   //Configure the logging
   ConfigureLogging();
   try
   {
    // Initial setup, create a ClientContext and a new operation instance.
    ClientContext clientContext = ClientContext.CreateFromFile(Directory.GetCurrentDirectory() + "/dc-services-sdk-config.json");
    CreatePDFOperation htmlToPDFOperation = CreatePDFOperation.CreateNew();

    // Set operation input from a source file.
    FileRef source = FileRef.CreateFromLocalFile(@"createPdfFromHtmlInput.zip");
    htmlToPDFOperation.SetInput(source);

    // Provide any custom configuration options for the operation.
    SetCustomOptions(htmlToPDFOperation);

    // Execute the operation.
    FileRef result = htmlToPDFOperation.Execute(clientContext);

    // Save the result to the specified location.
    result.SaveAs(Directory.GetCurrentDirectory() + "/output/createPdfFromHtmlOutput.pdf");
   }
   catch (ServiceApiException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch (SDKException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch (IOException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch (Exception ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
  }

  private static void SetCustomOptions(CreatePDFOperation htmlToPDFOperation)
  {
   // Define the page layout, in this case an 8 x 11.5 inch page (effectively portrait orientation).
   PageLayout pageLayout = new PageLayout();
   pageLayout.SetPageSize(8, 11.5);
   // Set the desired HTML-to-PDF conversion options.
   CreatePDFOptions htmlToPdfOptions = CreatePDFOptions.HtmlOptionsBuilder()
     .IncludeHeaderFooter(true)
     .WithPageLayout(pageLayout)
     . Build();
   htmlToPDFOperation.SetOptions(htmlToPdfOptions);
  }


  static void ConfigureLogging()
  {
   ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
   XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
  }
 }
}
  
Run the sample:
node src/createpdf/create-pdf-from-html.js
 const DCServicesSdk = require('@adobe/dc-services-node-sdk');

 const setCustomOptions = (htmlToPDFOperation) => {
   // Define the page layout, in this case an 8 x 11.5 inch page (effectively portrait orientation).
   const pageLayout = new DCServicesSdk.CreatePDF.options.PageLayout();
   pageLayout.setPageSize(8, 11.5);
   // Set the desired HTML-to-PDF conversion options.
   const htmlToPdfOptions = new DCServicesSdk.CreatePDF.options.html.CreatePDFFromHtmlOptions.Builder()
     .includesHeaderFooter(true)
     .withPageLayout(pageLayout)
     .build();
   htmlToPDFOperation.setOptions(htmlToPdfOptions);
 };


 try {
   // Initial setup, create a ClientContext using a config file, and a new operation instance.
   const clientContext = DCServicesSdk.ClientContext.createFromFile('dc-services-sdk-config.json'),
     htmlToPDFOperation = DCServicesSdk.CreatePDF.Operation.createNew();

   // Set operation input from a source file.
   const input = DCServicesSdk.FileRef.createFromLocalFile('resources/createPDFFromHtmlInput.zip');
   htmlToPDFOperation.setInput(input);

   // Provide any custom configuration options for the operation.
   setCustomOptions(htmlToPDFOperation);

   // Execute the operation and Save the result to the specified location.
   htmlToPDFOperation.execute(clientContext)
     .then(result => result.saveAsFile('output/createPdfFromHtmlOutput.pdf'))
     .catch(err => console.log('Exception encountered while executing operation', err));
 } catch (err) {
   console.log('Exception encountered while executing operation', err);
 }

Create a PDF from a URL

The sample file below converts an HTML page specified by an URL target into a PDF file. The primary difference between creating a PDF from a URL vs a local file (example above) is the creation of the input file reference:

  • Optional: Check whether the URL is valid (For example, with JAVA ukse MalformedURLException).

  • Specify the public URL as the input file reference with “text/html” as media type. (For example, sourceUrl in the JAVA example)

  • The URL must be a public URL and not a local hosted or intranet URL.

Run the sample:
mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.platform.operation.samples.createpdf.CreatePDFFromURL
// Get the samples from https://www.adobe.com/go/dcservicessdk_java_samples
import java.io.IOException;
import java.net.URL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adobe.platform.operation.ClientContext;
import com.adobe.platform.operation.exception.SdkException;
import com.adobe.platform.operation.exception.ServiceApiException;
import com.adobe.platform.operation.io.FileRef;
import com.adobe.platform.operation.pdfops.CreatePDFOperation;
import com.adobe.platform.operation.pdfops.options.createpdf.CreatePDFOptions;
import com.adobe.platform.operation.pdfops.options.createpdf.PageLayout;

public class CreatePDFFromURL {

   // Initialize the logger.
   private static final Logger LOGGER = LoggerFactory.getLogger(CreatePDFFromURL.class);

   public static void main(String[] args) {

       try {

           // Initial setup, create a ClientContext using a config file, and a new operation instance.
           ClientContext clientContext = ClientContext.createFromFile("dc-services-sdk-config.json");
           CreatePDFOperation htmlToPDFOperation = CreatePDFOperation.createNew();

           // Set operation input from a URL.
           FileRef source = FileRef.createFromURL(new URL("https://www.adobe.io"), CreatePDFOperation.SupportedSourceFormat.HTML.getMediaType());
           htmlToPDFOperation.setInput(source);

           // Provide any custom configuration options for the operation.
           setCustomOptions(htmlToPDFOperation);

           // Execute the operation.
           FileRef result = htmlToPDFOperation.execute(clientContext);

           // Save the result to the specified location.
           result.saveAs("output/createPdfFromUrlOutput.pdf");

       } catch (ServiceApiException | SdkException | IOException ex) {
           LOGGER.error("Exception encountered while executing operation", ex);
       }
   }

   private static void setCustomOptions(CreatePDFOperation htmlToPDFOperation) {
       // Define the page layout, in this case an 11.5 x 8 inch page (effectively landscape orientation).
       PageLayout pageLayout = new PageLayout();
       pageLayout.setPageSize(11.5, 8);
       // Set the desired HTML-to-PDF conversion options.
       CreatePDFOptions htmlToPdfOptions = CreatePDFOptions.htmlOptionsBuilder()
               .includeHeaderFooter(false).withPageLayout(pageLayout).build();
       htmlToPDFOperation.setOptions(htmlToPdfOptions);
   }
}
  
Run the sample:
cd CreatePDFFromURL/
dotnet run CreatePDFFromURL.csproj
// Get the samples from https://www.adobe.com/go/dcservicessdk_net_samples
using System;
using System.IO;
using log4net.Repository;
using log4net;
using System.Reflection;
using log4net.Config;
using Adobe.DocumentCloud.Services;
using Adobe.DocumentCloud.Services.pdfops;
using Adobe.DocumentCloud.Services.io;
using Adobe.DocumentCloud.Services.exception;
using Adobe.DocumentCloud.Services.options.createpdf;

namespace CreatePDFFromURL
{
 class Program
 {
  private static readonly ILog log = LogManager.GetLogger(typeof(Program));
  static void Main()
  {
   //Configure the logging
   ConfigureLogging();
   try
   {
    // Initial setup, create a ClientContext and a new operation instance.
    ClientContext clientContext = ClientContext.CreateFromFile(Directory.GetCurrentDirectory() + "/dc-services-sdk-config.json");
    CreatePDFOperation htmlToPDFOperation = CreatePDFOperation.CreateNew();

    // Set operation input from a URL.
    FileRef source = FileRef.CreateFromUrl(new Uri("https://www.adobe.io"), CreatePDFOperation.SupportedSourceFormat.HTML.GetMediaType());
    htmlToPDFOperation.SetInput(source);

    // Provide any custom configuration options for the operation.
    SetCustomOptions(htmlToPDFOperation);

    // Execute the operation.
    FileRef result = htmlToPDFOperation.Execute(clientContext);

    // Save the result to the specified location.
    result.SaveAs(Directory.GetCurrentDirectory() + "/output/createPdfFromURLOutput.pdf");
   }
   catch (ServiceApiException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch (SDKException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch (IOException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch(Exception ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
  }

  private static void SetCustomOptions(CreatePDFOperation htmlToPDFOperation)
  {
   // Define the page layout, in this case an 11.5 x 8 inch page (effectively landscape orientation).
   PageLayout pageLayout = new PageLayout();
   pageLayout.SetPageSize(11.5, 8);
   // Set the desired HTML-to-PDF conversion options.
   CreatePDFOptions htmlToPdfOptions = CreatePDFOptions.HtmlOptionsBuilder()
     .IncludeHeaderFooter(false).WithPageLayout(pageLayout).Build();
   htmlToPDFOperation.SetOptions(htmlToPdfOptions);
  }

  static void ConfigureLogging()
  {
   ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
   XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
  }
 }
}
  
Run the sample:
node src/createpdf/create-pdf-from-url.js
 const DCServicesSdk = require('@adobe/dc-services-node-sdk');

 const setCustomOptions = (htmlToPDFOperation) => {
   // Define the page layout, in this case an 8 x 11.5 inch page (effectively portrait orientation).
   const pageLayout = new DCServicesSdk.CreatePDF.options.PageLayout();
   pageLayout.setPageSize(8, 11.5);
   // Set the desired HTML-to-PDF conversion options.
   const htmlToPdfOptions = new DCServicesSdk.CreatePDF.options.html.CreatePDFFromHtmlOptions.Builder()
     .includesHeaderFooter(true)
     .withPageLayout(pageLayout)
     .build();
   htmlToPDFOperation.setOptions(htmlToPdfOptions);
 };

 try {
   // Initial setup, create a ClientContext using a config file, and a new operation instance.
   const clientContext = DCServicesSdk.ClientContext.createFromFile('dc-services-sdk-config.json'),
     htmlToPDFOperation = DCServicesSdk.CreatePDF.Operation.createNew();

   // Set operation input from a URL.
   const input = DCServicesSdk.FileRef.createFromUrl(new URL('https://www.adobe.io'), DCServicesSdk.CreatePDF.SupportedMediaTypes.html);
   htmlToPDFOperation.setInput(input);

   // Provide any custom configuration options for the operation.
   setCustomOptions(htmlToPDFOperation);

   // Execute the operation and Save the result to the specified location.
   htmlToPDFOperation.execute(clientContext)
     .then(result => result.saveAsFile('output/createPdfFromUrlOutput.pdf'))
     .catch(err => console.log('Exception encountered while executing operation', err));
 } catch (err) {
   console.log('Exception encountered while executing operation', err);
 }

Export a PDF

The sample below converts a PDF file into a number of supported formats such as:

  • Microsoft Office file formats

  • Text files

  • Images

Run the sample:
mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.platform.operation.samples.exportpdf.ExportPDFToDOCX
// Get the samples from https://www.adobe.com/go/dcservicessdk_java_samples
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adobe.platform.operation.ClientContext;
import com.adobe.platform.operation.exception.SdkException;
import com.adobe.platform.operation.exception.ServiceApiException;
import com.adobe.platform.operation.io.FileRef;
import com.adobe.platform.operation.pdfops.ExportPDFOperation;
import com.adobe.platform.operation.pdfops.options.exportpdf.ExportPDFTargetFormat;

public class ExportPDFToDOCX {

   // Initialize the logger.
   private static final Logger LOGGER = LoggerFactory.getLogger(ExportPDFToDOCX.class);

   public static void main(String[] args) {

       try {

           // Initial setup, create a ClientContext using a config file, and a new operation instance by specifying the intended export format.
           ClientContext clientContext = ClientContext.createFromFile("dc-services-sdk-config.json");
           ExportPDFOperation exportPdfOperation = ExportPDFOperation.createNew(ExportPDFTargetFormat.DOCX);

           // Set operation input from a local PDF file
           FileRef sourceFileRef = FileRef.createFromLocalFile("src/main/resources/exportPDFInput.pdf");
           exportPdfOperation.setInput(sourceFileRef);

           // Execute the operation.
           FileRef result = exportPdfOperation.execute(clientContext);

           // Save the result to the specified location.
           result.saveAs("output/exportPdfOutput.docx");

       } catch (ServiceApiException | IOException | SdkException ex) {
           LOGGER.error("Exception encountered while executing operation", ex);
       }
   }
}
  
Run the sample:
cd ExportPDFToDocx/
dotnet run ExportPDFToDocx.csproj
// Get the samples from https://www.adobe.com/go/dcservicessdk_net_samples
using Adobe.DocumentCloud.Services;
using Adobe.DocumentCloud.Services.exception;
using Adobe.DocumentCloud.Services.io;
using Adobe.DocumentCloud.Services.options.exportpdf;
using Adobe.DocumentCloud.Services.pdfops;
using log4net;
using log4net.Config;
using log4net.Repository;
using System;
using System.IO;
using System.Reflection;

namespace ExportPDFToDocx
{
 class Program
 {
  private static readonly ILog log = LogManager.GetLogger(typeof(Program));
  static void Main()
  {
   //Configure the logging
   ConfigureLogging();
   try
   {
    // Initial setup, create a ClientContext and a new operation instance by specifying the intended export format.
    ClientContext clientContext = ClientContext.CreateFromFile(Directory.GetCurrentDirectory() + "/dc-services-sdk-config.json");
    ExportPDFOperation exportPdfOperation = ExportPDFOperation.CreateNew(ExportPDFTargetFormat.DOCX);

    // Set operation input from a local PDF file
    FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"exportPdfInput.pdf");
    exportPdfOperation.SetInput(sourceFileRef);

    // Execute the operation.
    FileRef result = exportPdfOperation.Execute(clientContext);

    // Save the result to the specified location.
    result.SaveAs(Directory.GetCurrentDirectory() + "/output/exportPdfOutput.docx");
   }
   catch(ServiceApiException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch(SDKException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch(IOException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch (Exception ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
  }

  static void ConfigureLogging()
  {
   ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
   XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
  }
 }
}
  
Run the sample:
node src/exportpdf/export-pdf-to-docx.js
 const DCServicesSdk = require('@adobe/dc-services-node-sdk');

 try {
   // Initial setup, create a ClientContext using a config file, and a new operation instance by specifying the intended export format.
   const clientContext = DCServicesSdk.ClientContext.createFromFile('dc-services-sdk-config.json'),
     exportPDF = DCServicesSdk.ExportPDF,
     exportPdfOperation = exportPDF.Operation.createNew(exportPDF.SupportedTargetFormats.DOCX);

   // Set operation input from a source file
   const input = DCServicesSdk.FileRef.createFromLocalFile('resources/exportPDFInput.pdf');
   exportPdfOperation.setInput(input);

   // Execute the operation and Save the result to the specified location.
   exportPdfOperation.execute(clientContext)
     .then(result => result.saveAsFile('output/exportPdfOutput.docx'))
     .catch(err => console.log('Exception encountered while executing operation', err));
 } catch (err) {
   console.log('Exception encountered while executing operation', err);
 }

Export a PDF to images

The sample below converts a PDF file to one or more jpeg or png images. Exporting to an image produces a zip archive containing one image per page. Each image file name ends with “_<unpadded_page_index_number>”. For example, a PDF file with 15 pages will generate 15 image files. The first file’s name ends with “_1” and the last file’s name ends with “_15”.

Run the sample:
mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.platform.operation.samples.exportpdf.ExportPDFToJPEG
// Get the samples from https://www.adobe.com/go/dcservicessdk_java_samples
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adobe.platform.operation.ClientContext;
import com.adobe.platform.operation.exception.SdkException;
import com.adobe.platform.operation.exception.ServiceApiException;
import com.adobe.platform.operation.io.FileRef;
import com.adobe.platform.operation.pdfops.ExportPDFOperation;
import com.adobe.platform.operation.pdfops.options.exportpdf.ExportPDFTargetFormat;

public class ExportPDFToJPEG {

   // Initialize the logger.
   private static final Logger LOGGER = LoggerFactory.getLogger(ExportPDFToJPEG.class);

   public static void main(String[] args) {
       try {

           // Initial setup, create a ClientContext using a config file, and a new operation instance by specifying the intended export format.
           ClientContext clientContext = ClientContext.createFromFile("dc-services-sdk-config.json");
           ExportPDFOperation exportPdfOperation = ExportPDFOperation.createNew(ExportPDFTargetFormat.JPEG);

           // Set operation input from a source file.
           FileRef sourceFileRef = FileRef.createFromLocalFile("src/main/resources/exportPDFToImageInput.pdf");
           exportPdfOperation.setInput(sourceFileRef);

           // Execute the operation.
           FileRef result = exportPdfOperation.execute(clientContext);

           // Save the result to the specified location.
           result.saveAs("output/exportPDFToJPEG.zip");

       } catch (ServiceApiException | IOException | SdkException ex) {
           LOGGER.error("Exception encountered while executing operation", ex);
       }
   }
}
     
Run the sample:
cd ExportPDFToImage/
dotnet run ExportPDFToImage.csproj
// Get the samples from https://www.adobe.com/go/dcservicessdk_net_samples
using System.IO;
using System;
using log4net.Repository;
using log4net.Config;
using log4net;
using System.Reflection;
using Adobe.DocumentCloud.Services;
using Adobe.DocumentCloud.Services.pdfops;
using Adobe.DocumentCloud.Services.options.exportpdf;
using Adobe.DocumentCloud.Services.io;
using Adobe.DocumentCloud.Services.exception;

namespace ExportPDFToImage
{
 class Program
 {
  private static readonly ILog log = LogManager.GetLogger(typeof(Program));
  static void Main()
  {
   //Configure the logging
   ConfigureLogging();
   try
   {
    // Initial setup, create a ClientContext and a new operation instance by specifying the intended export format.
    ClientContext clientContext = ClientContext.CreateFromFile(Directory.GetCurrentDirectory() + "/dc-services-sdk-config.json");
    ExportPDFOperation exportPdfOperation = ExportPDFOperation.CreateNew(ExportPDFTargetFormat.JPEG);

    // Set operation input from a source file.
    FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"exportPdfToImageInput.pdf");
    exportPdfOperation.SetInput(sourceFileRef);

    // Execute the operation.
    FileRef result = exportPdfOperation.Execute(clientContext);

    // Save the result to the specified location.
    result.SaveAs(Directory.GetCurrentDirectory() + "/output/exportPdfToImageOutput.zip");
   }
   catch (ServiceApiException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch (SDKException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch (IOException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch (Exception ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
  }

  static void ConfigureLogging()
  {
   ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
   XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
  }
 }
}
    
Run the sample:
node src/exportpdf/export-pdf-to-jpeg.js
 const DCServicesSdk = require('@adobe/dc-services-node-sdk');

 try {
   // Initial setup, create a ClientContext using a config file, and a new operation instance by specifying the intended export format.
   const clientContext = DCServicesSdk.ClientContext.createFromFile('dc-services-sdk-config.json'),
     exportPDF = DCServicesSdk.ExportPDF,
     exportPdfOperation = exportPDF.Operation.createNew(exportPDF.SupportedTargetFormats.JPEG);

   // Set operation input from a source file
   const input = DCServicesSdk.FileRef.createFromLocalFile('resources/exportPDFToImageInput.pdf');
   exportPdfOperation.setInput(input);

   // Execute the operation and Save the result to the specified location.
   exportPdfOperation.execute(clientContext)
     .then(result => result.saveAsFile('output/exportPDFToJPEG.zip'))
     .catch(err => console.log('Exception encountered while executing operation', err));
 } catch (err) {
   console.log('Exception encountered while executing operation', err);

Combine files

This sample combines up to 12 PDF files into a single PDF file.

Run the sample:
mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.platform.operation.samples.combine.CombinePDF
// Get the samples from https://www.adobe.com/go/dcservicessdk_java_samples
import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.platform.operation.ClientContext;
import com.adobe.platform.operation.exception.SdkException;
import com.adobe.platform.operation.exception.ServiceApiException;
import com.adobe.platform.operation.io.FileRef;
import com.adobe.platform.operation.pdfops.CombineFilesOperation;
import com.adobe.platform.operation.samples.exportpdf.ExportPDFToJPEG;

public class CombinePDF {

   // Initialize the logger.
   private static final Logger LOGGER = LoggerFactory.getLogger(ExportPDFToJPEG.class);

   public static void main(String[] args) {

       try {

           // Initial setup, create a ClientContext using a config file, and a new operation instance.
           ClientContext clientContext = ClientContext.createFromFile("dc-services-sdk-config.json");
           CombineFilesOperation combineFilesOperation = CombineFilesOperation.createNew();

           // Add operation input from source files.
           FileRef combineSource1 = FileRef.createFromLocalFile("src/main/resources/combineFilesInput1.pdf");
           FileRef combineSource2 = FileRef.createFromLocalFile("src/main/resources/combineFilesInput2.pdf");
           combineFilesOperation.addInput(combineSource1);
           combineFilesOperation.addInput(combineSource2);

           // Execute the operation.
           FileRef result = combineFilesOperation.execute(clientContext);

           // Save the result to the specified location.
           result.saveAs("output/combineFilesOutput.pdf");

       } catch (IOException | ServiceApiException | SdkException e) {
           LOGGER.error("Exception encountered while executing operation", e);
       }
   }
}
     
Run the sample:
cd CombinePDF/
dotnet run CombinePDF.csproj
// Get the samples from https://www.adobe.com/go/dcservicessdk_net_samples
using System;
using System.IO;
using log4net;
using log4net.Config;
using System.Reflection;
using log4net.Repository;
using Adobe.DocumentCloud.Services;
using Adobe.DocumentCloud.Services.pdfops;
using Adobe.DocumentCloud.Services.io;
using Adobe.DocumentCloud.Services.exception;

namespace CombinePDF
{
 class Program
 {
  private static readonly ILog log = LogManager.GetLogger(typeof(Program));
  static void Main()
  {
   //Configure the logging
   ConfigureLogging();
   try
   {
    // Initial setup, create a ClientContext and a new operation instance.
    ClientContext clientContext = ClientContext.CreateFromFile(Directory.GetCurrentDirectory() + "/dc-services-sdk-config.json");
    CombineFilesOperation combineFilesOperation = CombineFilesOperation.CreateNew();

    // Add operation input from source files.
    FileRef combineSource1 = FileRef.CreateFromLocalFile(@"combineFilesInput1.pdf");
    FileRef combineSource2 = FileRef.CreateFromLocalFile(@"combineFilesInput2.pdf");
    combineFilesOperation.AddInput(combineSource1);
    combineFilesOperation.AddInput(combineSource2);

    // Execute the operation.
    FileRef result = combineFilesOperation.Execute(clientContext);

    // Save the result to the specified location.
    result.SaveAs(Directory.GetCurrentDirectory() + "/output/combineFilesOutput.pdf");

   }
   catch (ServiceApiException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch (SDKException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch(IOException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch (Exception ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
  }

  static void ConfigureLogging()
  {
   ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
   XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
  }
 }
}
    
Run the sample:
node src/combine/combine-pdf.js
 const DCServicesSdk = require('@adobe/dc-services-node-sdk');

 try {
   // Initial setup, create a ClientContext using a config file, and a new operation instance.
   const clientContext = DCServicesSdk.ClientContext.createFromFile('dc-services-sdk-config.json'),
     combineFilesOperation = DCServicesSdk.CombineFiles.Operation.createNew();

   // Add operation input from source files.
   const combineSource1 = DCServicesSdk.FileRef.createFromLocalFile('resources/combineFilesInput1.pdf'),
     combineSource2 = DCServicesSdk.FileRef.createFromLocalFile('resources/combineFilesInput2.pdf');
   combineFilesOperation.addInput(combineSource1);
   combineFilesOperation.addInput(combineSource2);

   // Execute the operation and Save the result to the specified location.
   combineFilesOperation.execute(clientContext)
     .then(result => result.saveAsFile('output/combineFilesOutput.pdf'))
     .catch(err => console.log('Exception encountered while executing operation', err));
 } catch (err) {
   console.log('Exception encountered while executing operation', err);
 }

Combine pages from multiple files

This combine sample combines specific pages from up to 12 different PDF files into a single PDF file. Optional arguments allow specifying page ranges for each file to combine in the output file.

Run the sample:
mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.platform.operation.samples.combine.CombinePDFWithPageRanges
// Get the samples from https://www.adobe.com/go/dcservicessdk_java_samples
import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.platform.operation.ClientContext;
import com.adobe.platform.operation.exception.SdkException;
import com.adobe.platform.operation.exception.ServiceApiException;
import com.adobe.platform.operation.io.FileRef;
import com.adobe.platform.operation.pdfops.CombineFilesOperation;
import com.adobe.platform.operation.pdfops.options.PageRanges;

public class CombinePDFWithPageRanges {

   // Initialize the logger.
   private static final Logger LOGGER = LoggerFactory.getLogger(CombinePDFWithPageRanges.class);

   public static void main(String[] args) {

       try {

           // Initial setup, create a ClientContext using a config file, and a new operation instance.
           ClientContext clientContext = ClientContext.createFromFile("dc-services-sdk-config.json");
           CombineFilesOperation combineFilesOperation = CombineFilesOperation.createNew();

           // Create a FileRef instance from a local file.
           FileRef firstFileToCombine = FileRef.createFromLocalFile("src/main/resources/combineFileWithPageRangeInput1.pdf");
           PageRanges pageRangesForFirstFile = getPageRangeForFirstFile();
           // Add the first file as input to the operation, along with its page range.
           combineFilesOperation.addInput(firstFileToCombine, pageRangesForFirstFile);

           // Create a second FileRef instance using a local file.
           FileRef secondFileToCombine = FileRef.createFromLocalFile("src/main/resources/combineFileWithPageRangeInput2.pdf");
           PageRanges pageRangesForSecondFile = getPageRangeForSecondFile();
           // Add the second file as input to the operation, along with its page range.
           combineFilesOperation.addInput(secondFileToCombine, pageRangesForSecondFile);

           // Execute the operation.
           FileRef result = combineFilesOperation.execute(clientContext);

           // Save the result to the specified location.
           result.saveAs("output/combineFilesWithPageOptionsOutput.pdf");

       } catch (ServiceApiException | IOException | SdkException ex) {
           LOGGER.error("Exception encountered while executing operation", ex);
       }
   }

   private static PageRanges getPageRangeForSecondFile() {
       // Specify which pages of the second file are to be included in the combined file.
       PageRanges pageRangesForSecondFile = new PageRanges();
       // Add all pages including and after page 3.
       pageRangesForSecondFile.addAllFrom(3);
       return pageRangesForSecondFile;
   }

   private static PageRanges getPageRangeForFirstFile() {
       // Specify which pages of the first file are to be included in the combined file.
       PageRanges pageRangesForFirstFile = new PageRanges();
       // Add page 1.
       pageRangesForFirstFile.addSinglePage(1);
       // Add page 2.
       pageRangesForFirstFile.addSinglePage(2);
       // Add pages 3 to 4.
       pageRangesForFirstFile.addRange(3, 4);
       return pageRangesForFirstFile;
   }
}
     
Run the sample:
cd CombinePDFWithPageRanges/
dotnet run CombinePDFWithPageRanges.csproj
// Get the samples from https://www.adobe.com/go/dcservicessdk_net_samples
using System;
using System.IO;
using log4net.Repository;
using log4net;
using log4net.Config;
using System.Reflection;
using Adobe.DocumentCloud.Services;
using Adobe.DocumentCloud.Services.pdfops;
using Adobe.DocumentCloud.Services.io;
using Adobe.DocumentCloud.Services.options;
using Adobe.DocumentCloud.Services.exception;

namespace CombinePDFWithPageRanges
{
 class Program
 {
  private static readonly ILog log = LogManager.GetLogger(typeof(Program));
  static void Main()
  {
   //Configure the logging
   ConfigureLogging();
   try
   {

    // Initial setup, create a ClientContext and a new operation instance.
    ClientContext clientContext = ClientContext.CreateFromFile(Directory.GetCurrentDirectory() + "/dc-services-sdk-config.json");
    CombineFilesOperation combineFilesOperation = CombineFilesOperation.CreateNew();

    // Create a FileRef instance from a local file.
    FileRef firstFileToCombine = FileRef.CreateFromLocalFile(@"combineFileWithPageRangeInput1.pdf");
    PageRanges pageRangesForFirstFile = GetPageRangeForFirstFile();
    // Add the first file as input to the operation, along with its page range.
    combineFilesOperation.AddInput(firstFileToCombine, pageRangesForFirstFile);

    // Create a second FileRef instance using a local file.
    FileRef secondFileToCombine = FileRef.CreateFromLocalFile(@"combineFileWithPageRangeInput2.pdf");
    PageRanges pageRangesForSecondFile = GetPageRangeForSecondFile();
    // Add the second file as input to the operation, along with its page range.
    combineFilesOperation.AddInput(secondFileToCombine, pageRangesForSecondFile);

    // Execute the operation.
    FileRef result = combineFilesOperation.Execute(clientContext);

    // Save the result to the specified location.
    result.SaveAs(Directory.GetCurrentDirectory() + "/output/combineFilesOutput.pdf");

   }
   catch (ServiceApiException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch(SDKException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch(IOException ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
   catch(Exception ex)
   {
    log.Error("Exception encountered while executing operation", ex);
   }
  }

  private static PageRanges GetPageRangeForSecondFile()
  {
   // Specify which pages of the second file are to be included in the combined file.
   PageRanges pageRangesForSecondFile = new PageRanges();
   // Add all pages including and after page 5.
   pageRangesForSecondFile.AddAllFrom(5);
   return pageRangesForSecondFile;
  }

  private static PageRanges GetPageRangeForFirstFile()
  {
   // Specify which pages of the first file are to be included in the combined file.
   PageRanges pageRangesForFirstFile = new PageRanges();
   // Add page 2.
   pageRangesForFirstFile.AddSinglePage(2);
   // Add page 3.
   pageRangesForFirstFile.AddSinglePage(3);
   // Add pages 5 to 7.
   pageRangesForFirstFile.AddRange(5, 7);
   return pageRangesForFirstFile;
  }

  static void ConfigureLogging()
  {
   ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
   XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
  }
 }
}
    
Run the sample:
node src/combine/combine-pdf-with-page-ranges.js
 const DCServicesSdk = require('@adobe/dc-services-node-sdk');

 const getPageRangesForFirstFile = () => {
   // Specify which pages of the first file are to be included in the combined file.
   const pageRangesForFirstFile = new DCServicesSdk.PageRanges();
   // Add page 1.
   pageRangesForFirstFile.addSinglePage(1);
   // Add page 2.
   pageRangesForFirstFile.addSinglePage(2);
   // Add pages 3 to 4.
   pageRangesForFirstFile.addPageRange(3, 4);
   return pageRangesForFirstFile;
 };

 const getPageRangesForSecondFile = () => {
   // Specify which pages of the second file are to be included in the combined file.
   const pageRangesForSecondFile = new DCServicesSdk.PageRanges();
   // Add all pages including and after page 3.
   pageRangesForSecondFile.addAllFrom(3);
   return pageRangesForSecondFile;
 };

 try {
   // Initial setup, create a ClientContext using a config file, and a new operation instance.
   const clientContext = DCServicesSdk.ClientContext.createFromFile('dc-services-sdk-config.json'),
     combineFilesOperation = DCServicesSdk.CombineFiles.Operation.createNew();

   // Create a FileRef instance from a local file.
   const combineSource1 = DCServicesSdk.FileRef.createFromLocalFile('resources/combineFilesInput1.pdf'),
     pageRangesForFirstFile = getPageRangesForFirstFile();
   // Add the first file as input to the operation, along with its page range.
   combineFilesOperation.addInput(combineSource1, pageRangesForFirstFile);

   // Create a second FileRef instance using a local file.
   const combineSource2 = DCServicesSdk.FileRef.createFromLocalFile('resources/combineFilesInput2.pdf'),
     pageRangesForSecondFile = getPageRangesForSecondFile();
   // Add the second file as input to the operation, along with its page range.
   combineFilesOperation.addInput(combineSource2, pageRangesForSecondFile);

   // Execute the operation and Save the result to the specified location.
   combineFilesOperation.execute(clientContext)
     .then(result => result.saveAsFile('output/combineFilesWithPageRangesOutput.pdf'))
     .catch(err => console.log('Exception encountered while executing operation', err));
 } catch (err) {
   console.log('Exception encountered while executing operation', err);
 }