Export PDF
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
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.exportpdf.ExportPDFToDOCX45public class ExportPDFToDOCX {67 // Initialize the logger.8 private static final Logger LOGGER = LoggerFactory.getLogger(ExportPDFToDOCX.class);910 public static void main(String[] args) {1112 try {13 // Initial setup, create credentials instance.14 Credentials credentials = Credentials.serviceAccountCredentialsBuilder()15 .fromFile("pdfservices-api-credentials.json")16 .build();17 //Create an ExecutionContext using credentials and create a new operation instance.18 ExecutionContext executionContext = ExecutionContext.create(credentials);19 ExportPDFOperation exportPdfOperation = ExportPDFOperation.createNew(ExportPDFTargetFormat.DOCX);2021 // Set operation input from a local PDF file22 FileRef sourceFileRef = FileRef.createFromLocalFile("src/main/resources/exportPDFInput.pdf");23 exportPdfOperation.setInput(sourceFileRef);2425 // Execute the operation.26 FileRef result = exportPdfOperation.execute(executionContext);2728 // Save the result to the specified location.29 result.saveAs("output/exportPdfOutput.docx");3031 } catch (ServiceApiException | IOException | SdkException | ServiceUsageException ex) {32 LOGGER.error("Exception encountered while executing operation", ex);33 }34 }35 }36
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd ExportPDFToDocx/4// dotnet run ExportPDFToDocx.csproj56 namespace ExportPDFToDocx7 {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 and create a new operation instance.23 ExecutionContext executionContext = ExecutionContext.Create(credentials);24 ExportPDFOperation exportPdfOperation = ExportPDFOperation.CreateNew(ExportPDFTargetFormat.DOCX);2526 // Set operation input from a local PDF file27 FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"exportPdfInput.pdf");28 exportPdfOperation.SetInput(sourceFileRef);2930 // Execute the operation.31 FileRef result = exportPdfOperation.Execute(executionContext);3233 // Save the result to the specified location.34 result.SaveAs(Directory.GetCurrentDirectory() + "/output/exportPdfOutput.docx");35 }36 catch (ServiceUsageException ex)37 {38 log.Error("Exception encountered while executing operation", ex);39 }40 // Catch more errors here. . .41 }4243 static void ConfigureLogging()44 {45 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());46 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));47 }48 }49 }
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/exportpdf/export-pdf-to-docx.js45const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');67 try {8 // Initial setup, create credentials instance.9 const credentials = PDFServicesSdk.Credentials10 .serviceAccountCredentialsBuilder()11 .fromFile("pdfservices-api-credentials.json")12 .build();1314 //Create an ExecutionContext using credentials and create a new operation instance.15 const executionContext = PDFServicesSdk.ExecutionContext.create(credentials),16 exportPDF = PDFServicesSdk.ExportPDF,17 exportPdfOperation = exportPDF.Operation.createNew(exportPDF.SupportedTargetFormats.DOCX);1819 // Set operation input from a source file20 const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/exportPDFInput.pdf');21 exportPdfOperation.setInput(input);2223 // Execute the operation and Save the result to the specified location.24 exportPdfOperation.execute(executionContext)25 .then(result => result.saveAsFile('output/exportPdfOutput.docx'))26 .catch(err => {27 if(err instanceof PDFServicesSdk.Error.ServiceApiError28 || err instanceof PDFServicesSdk.Error.ServiceUsageError) {29 console.log('Exception encountered while executing operation', err);30 } else {31 console.log('Exception encountered while executing operation', err);32 }33 });34 } catch (err) {35 console.log('Exception encountered while executing operation', err);36 }
Copied to your clipboard1// Please refer our REST API docs for more information2// https://documentcloud.adobe.com/document-services/index.html#post-exportPDF34curl --location --request POST 'https://cpf-ue1.adobe.io/ops/:create?respondWith=%7B%22reltype%22%3A%20%22http%3A%2F%2Fns.adobe.com%2Frel%2Fprimary%22%7D' \5--header 'Authorization: Bearer {{Placeholder for token}}' \6--header 'Accept: application/json, text/plain, */*' \7--header 'x-api-key: {{Placeholder for client_id}}' \8--header 'Prefer: respond-async,wait=0' \9--form 'contentAnalyzerRequests="{10 \"cpf:inputs\": {11 \"params\": {12 \"cpf:inline\": {13 \"targetFormat\": \"docx\"14 }15 },16 \"documentIn\": {17 \"cpf:location\": \"InputFile0\",18 \"dc:format\": \"application/pdf\"19 }20 },21 \"cpf:engine\": {22 \"repo:assetId\": \"urn:aaid:cpf:Service-26c7fda2890b44ad9a82714682e35888\"23 },24 \"cpf:outputs\": {25 \"documentOut\": {26 \"cpf:location\": \"multipartLabelOut\",27 \"dc:format\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\"28 }29 }30}"' \31--form 'InputFile0=@"{{Placeholder for input file (absolute path)}}"'
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".
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.exportpdf.ExportPDFToJPEG45 public class ExportPDFToJPEG {67 // Initialize the logger.8 private static final Logger LOGGER = LoggerFactory.getLogger(ExportPDFToJPEG.class);910 public static void main(String[] args) {11 try {1213 // Initial setup, create credentials instance.14 Credentials credentials = Credentials.serviceAccountCredentialsBuilder()15 .fromFile("pdfservices-api-credentials.json")16 .build();1718 //Create an ExecutionContext using credentials and create a new operation instance.19 ExecutionContext executionContext = ExecutionContext.create(credentials);20 ExportPDFOperation exportPdfOperation = ExportPDFOperation.createNew(ExportPDFTargetFormat.JPEG);2122 // Set operation input from a source file.23 FileRef sourceFileRef = FileRef.createFromLocalFile("src/main/resources/exportPDFToImageInput.pdf");24 exportPdfOperation.setInput(sourceFileRef);2526 // Execute the operation.27 FileRef result = exportPdfOperation.execute(executionContext);2829 // Save the result to the specified location.30 result.saveAs("output/exportPDFToJPEG.zip");3132 } catch (ServiceApiException | IOException | SdkException | ServiceUsageException ex) {33 LOGGER.error("Exception encountered while executing operation", ex);34 }35 }36 }37
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd ExportPDFToImage/4// dotnet run ExportPDFToImage.csproj56 namespace ExportPDFToImage7 {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 and create a new operation instance.23 ExecutionContext executionContext = ExecutionContext.Create(credentials);24 ExportPDFOperation exportPdfOperation = ExportPDFOperation.CreateNew(ExportPDFTargetFormat.JPEG);2526 // Set operation input from a source file.27 FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"exportPdfToImageInput.pdf");28 exportPdfOperation.SetInput(sourceFileRef);2930 // Execute the operation.31 FileRef result = exportPdfOperation.Execute(executionContext);3233 // Save the result to the specified location.34 result.SaveAs(Directory.GetCurrentDirectory() + "/output/exportPdfToImageOutput.zip");35 }36 catch (ServiceUsageException ex)37 {38 log.Error("Exception encountered while executing operation", ex);39 }40 // Catch more errors here. . .41 }4243 static void ConfigureLogging()44 {45 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());46 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));47 }48 }49 }
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/exportpdf/export-pdf-to-jpeg.js45 const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');67 try {8 // Initial setup, create credentials instance.9 const credentials = PDFServicesSdk.Credentials10 .serviceAccountCredentialsBuilder()11 .fromFile("pdfservices-api-credentials.json")12 .build();1314 //Create an ExecutionContext using credentials and create a new operation instance.15 const executionContext = PDFServicesSdk.ExecutionContext.create(credentials),16 exportPDF = PDFServicesSdk.ExportPDF,17 exportPdfOperation = exportPDF.Operation.createNew(exportPDF.SupportedTargetFormats.JPEG);1819 // Set operation input from a source file20 const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/exportPDFToImageInput.pdf');21 exportPdfOperation.setInput(input);2223 // Execute the operation and Save the result to the specified location.24 exportPdfOperation.execute(executionContext)25 .then(result => result.saveAsFile('output/exportPDFToJPEG.zip'))26 .catch(err => {27 if(err instanceof PDFServicesSdk.Error.ServiceApiError28 || err instanceof PDFServicesSdk.Error.ServiceUsageError) {29 console.log('Exception encountered while executing operation', err);30 } else {31 console.log('Exception encountered while executing operation', err);32 }33 });34 } catch (err) {35 console.log('Exception encountered while executing operation', err);36 }
Copied to your clipboard1// Please refer our REST API docs for more information2// https://documentcloud.adobe.com/document-services/index.html#post-exportPDF34curl --location --request POST 'https://cpf-ue1.adobe.io/ops/:create?respondWith=%7B%22reltype%22%3A%20%22http%3A%2F%2Fns.adobe.com%2Frel%2Fprimary%22%7D' \5--header 'Authorization: Bearer {{Placeholder for token}}' \6--header 'Accept: application/json, text/plain, */*' \7--header 'x-api-key: {{Placeholder for client_id}}' \8--header 'Prefer: respond-async,wait=0' \9--form 'contentAnalyzerRequests="{10 \"cpf:inputs\": {11 \"params\": {12 \"cpf:inline\": {13 \"targetFormat\": \"jpeg\"14 }15 },16 \"documentIn\": {17 \"cpf:location\": \"InputFile0\",18 \"dc:format\": \"application/pdf\"19 }20 },21 \"cpf:engine\": {22 \"repo:assetId\": \"urn:aaid:cpf:Service-26c7fda2890b44ad9a82714682e35888\"23 },24 \"cpf:outputs\": {25 \"documentOut\": {26 \"cpf:location\": \"multipartLabelOut\",27 \"dc:format\": \"application/zip\"28 }29 }30}"' \31--form 'InputFile0=@"{{Placeholder for input file (absolute path)}}"'
Export a PDF to list of images
The sample below converts a PDF file to one or more jpeg or png images.
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.exportpdf.ExportPDFToJPEGList45 public class ExportPDFToJPEGList {67 // Initialize the logger.8 private static final Logger LOGGER = LoggerFactory.getLogger(ExportPDFToJPEG.class);910 public static void main(String[] args) {11 try {1213 // Initial setup, create credentials instance.14 Credentials credentials = Credentials.serviceAccountCredentialsBuilder()15 .fromFile("pdfservices-api-credentials.json")16 .build();1718 //Create an ExecutionContext using credentials and create a new operation instance.19 ExecutionContext executionContext = ExecutionContext.create(credentials);20 ExportPDFToImagesOperation exportPDFToImagesOperation = ExportPDFToImagesOperation.createNew(ExportPDFToImagesTargetFormat.JPEG);2122 // Set operation input from a source file.23 FileRef sourceFileRef = FileRef.createFromLocalFile("src/main/resources/exportPDFToImageInput.pdf");24 exportPDFToImagesOperation.setInput(sourceFileRef);2526 // Execute the operation.27 List<FileRef> results = exportPDFToImagesOperation.execute(executionContext);2829 // Save the result to the specified location.30 int index = 0;31 for(FileRef result : results) {32 result.saveAs("output/exportPDFToImagesOutput_" + index + ".jpeg");33 index++;34 }35 } catch (ServiceApiException | IOException | SdkException | ServiceUsageException ex) {36 LOGGER.error("Exception encountered while executing operation", ex);37 }38 }39 }
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd ExportPDFToJPEGList/4// dotnet run ExportPDFToJPEGList.csproj56namespace7{8 class Program ExportPDFToJPEGList9 {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 and create a new operation instance.23 ExecutionContext executionContext = ExecutionContext.Create(credentials);24 ExportPDFToImagesOperation exportPDFToImagesOperation = ExportPDFToImagesOperation.CreateNew(ExportPDFToImagesTargetFormat.JPEG);2526 // Set operation input from a source file.27 FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"exportPDFToImagesInput.pdf");28 exportPDFToImagesOperation.SetInput(sourceFileRef);2930 // Execute the operation.31 List<FileRef> result = exportPDFToImagesOperation.Execute(executionContext);3233 // Save the result to the specified location.34 int index = 0;35 foreach (FileRef fileRef in result)36 {37 fileRef.SaveAs(Directory.GetCurrentDirectory() + "/output/exportPDFToImagesOutput_" + index + ".jpeg");38 index++;39 }40 }41 catch (ServiceUsageException ex)42 {43 log.Error("Exception encountered while executing operation", ex);44 }45 // Catch more errors here. . .46 }4748 static void ConfigureLogging()49 {50 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());51 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));52 }53 }54}
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/exportpdf/export-pdf-to-jpeg-list.js45const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');67try {8 // Initial setup, create credentials instance.9 const credentials = PDFServicesSdk.Credentials10 .serviceAccountCredentialsBuilder()11 .fromFile("pdfservices-api-credentials.json")12 .build();1314 //Create an ExecutionContext using credentials and create a new operation instance.15 const executionContext = PDFServicesSdk.ExecutionContext.create(credentials),16 exportPDF = PDFServicesSdk.ExportPDF,17 exportPdfToImagesOperation = exportPDFToImages.Operation.createNew(exportPDFToImages.SupportedTargetFormats.JPEG);1819 // Set operation input from a source file20 const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/exportPDFToImageInput.pdf');21 exportPdfToImagesOperation.setInput(input);2223 // Execute the operation and Save the result to the specified location.24 exportPdfToImagesOperation.execute(executionContext)25 .then(result => {26 let saveFilesPromises = [];27 for(let i = 0; i < result.length; i++){28 saveFilesPromises.push(result[i].saveAsFile(`output/exportPDFToJPEGOutput_${i}.jpeg`));29 }30 return Promise.all(saveFilesPromises);31 })32 .catch(err => {33 if(err instanceof PDFServicesSdk.Error.ServiceApiError34 || err instanceof PDFServicesSdk.Error.ServiceUsageError) {35 console.log('Exception encountered while executing operation', err);36 } else {37 console.log('Exception encountered while executing operation', err);38 }39 });40} catch (err) {41 console.log('Exception encountered while executing operation', err);42}
Copied to your clipboard1// Please refer our REST API docs for more information2// https://documentcloud.adobe.com/document-services/index.html#post-exportPDF34curl --location --request POST 'https://cpf-ue1.adobe.io/ops/:create?respondWith=%7B%22reltype%22%3A%20%22http%3A%2F%2Fns.adobe.com%2Frel%2Fprimary%22%7D' \5--header 'Authorization: Bearer {{Placeholder for token}}' \6--header 'Accept: application/json, text/plain, */*' \7--header 'x-api-key: {{Placeholder for client_id}}' \8--header 'Prefer: respond-async,wait=0' \9--form 'contentAnalyzerRequests="{10 \"cpf:inputs\": {11 \"params\": {12 \"cpf:inline\": {13 \"targetFormat\": \"jpeg\",14 \"outputType\": \"listOfPageImages\"15 }16 },17 \"documentIn\": {18 \"cpf:location\": \"InputFile0\",19 \"dc:format\": \"application/pdf\"20 }21 },22 \"cpf:engine\": {23 \"repo:assetId\": \"urn:aaid:cpf:Service-26c7fda2890b44ad9a82714682e35888\"24 },25 \"cpf:outputs\": {26 \"documentOutList\": {27 \"cpf:location\": \"multipartLabelOut\",28 \"dc:format\": \"image/jpeg\"29 }30 }31}"' \32--form 'InputFile0=@"{{Placeholder for input file (absolute path)}}"'