Export PDF
Export a source PDF file into doc, docx, jpeg, png, pptx, rtf, xlsx.
REST API
See our public API Reference for :
Export a PDF
The sample below converts a PDF file into a number of supported formats such as:
- Microsoft Office file formats
- Text files
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.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 (InputStream inputStream = Files.newInputStream(new File("src/main/resources/exportPDFInput.pdf").toPath())) {13 // Initial setup, create credentials instance14 Credentials credentials = new ServicePrincipalCredentials(15 System.getenv("PDF_SERVICES_CLIENT_ID"),16 System.getenv("PDF_SERVICES_CLIENT_SECRET"));1718 // Creates a PDF Services instance19 PDFServices pdfServices = new PDFServices(credentials);2021 // Creates an asset(s) from source file(s) and upload22 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());2324 // Create parameters for the job25 ExportPDFParams exportPDFParams = ExportPDFParams.exportPDFParamsBuilder(ExportPDFTargetFormat.DOCX)26 .build();2728 // Creates a new job instance29 ExportPDFJob exportPDFJob = new ExportPDFJob(asset, exportPDFParams);3031 // Submit the job and gets the job result32 String location = pdfServices.submit(exportPDFJob);33 PDFServicesResponse<ExportPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, ExportPDFResult.class);3435 // Get content from the resulting asset(s)36 Asset resultAsset = pdfServicesResponse.getResult().getAsset();37 StreamAsset streamAsset = pdfServices.getContent(resultAsset);3839 // Creates an output stream and copy stream asset's content to it40 Files.createDirectories(Paths.get("output/"));41 OutputStream outputStream = Files.newOutputStream(new File("output/exportPdfOutput.docx").toPath());42 LOGGER.info("Saving asset at output/exportPdfOutput.docx");43 IOUtils.copy(streamAsset.getInputStream(), outputStream);44 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {45 LOGGER.error("Exception encountered while executing operation", ex);46 }47 }48 }49
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.ServicePrincipalCredentialsBuilder()19 .WithClientId("PDF_SERVICES_CLIENT_ID")20 .WithClientSecret("PDF_SERVICES_CLIENT_SECRET")21 .Build();2223 //Create an ExecutionContext using credentials and create a new operation instance.24 ExecutionContext executionContext = ExecutionContext.Create(credentials);25 ExportPDFOperation exportPdfOperation = ExportPDFOperation.CreateNew(ExportPDFTargetFormat.DOCX);2627 // Set operation input from a local PDF file28 FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"exportPdfInput.pdf");29 exportPdfOperation.SetInput(sourceFileRef);3031 // Execute the operation.32 FileRef result = exportPdfOperation.Execute(executionContext);3334 // Save the result to the specified location.35 result.SaveAs(Directory.GetCurrentDirectory() + "/output/exportPdfOutput.docx");36 }37 catch (ServiceUsageException ex)38 {39 log.Error("Exception encountered while executing operation", ex);40 }41 // Catch more errors here. . .42 }4344 static void ConfigureLogging()45 {46 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());47 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));48 }49 }50 }
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 {6 ServicePrincipalCredentials,7 PDFServices,8 MimeType,9 ExportPDFJob,10 ExportPDFParams,11 ExportPDFTargetFormat,12 ExportPDFResult,13 SDKError,14 ServiceUsageError,15 ServiceApiError16} = require("@adobe/pdfservices-node-sdk");17const fs = require("fs");1819(async () => {20 let readStream;21 try {22 // Initial setup, create credentials instance23 const credentials = new ServicePrincipalCredentials({24 clientId: process.env.PDF_SERVICES_CLIENT_ID,25 clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET26 });2728 // Creates a PDF Services instance29 const pdfServices = new PDFServices({credentials});3031 // Creates an asset(s) from source file(s) and upload32 readStream = fs.createReadStream("./exportPDFInput.pdf");33 const inputAsset = await pdfServices.upload({34 readStream,35 mimeType: MimeType.PDF36 });3738 // Create parameters for the job39 const params = new ExportPDFParams({40 targetFormat: ExportPDFTargetFormat.DOCX41 });4243 // Creates a new job instance44 const job = new ExportPDFJob({inputAsset, params});4546 // Submit the job and get the job result47 const pollingURL = await pdfServices.submit({job});48 const pdfServicesResponse = await pdfServices.getJobResult({49 pollingURL,50 resultType: ExportPDFResult51 });5253 // Get content from the resulting asset(s)54 const resultAsset = pdfServicesResponse.result.asset;55 const streamAsset = await pdfServices.getContent({asset: resultAsset});5657 // Creates an output stream and copy stream asset's content to it58 const outputFilePath = "./exportPDFToDOCXOutput.docx";59 console.log(`Saving asset at ${outputFilePath}`);6061 const outputStream = fs.createWriteStream(outputFilePath);62 streamAsset.readStream.pipe(outputStream);63 } catch (err) {64 if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {65 console.log("Exception encountered while executing operation", err);66 } else {67 console.log("Exception encountered while executing operation", err);68 }69 } finally {70 readStream?.destroy();71 }72})();
Copied to your clipboard1// Please refer our REST API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Export-PDF34curl --location --request POST 'https://pdf-services.adobe.io/operation/exportpdf' \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 "targetFormat": "docx"11}'
Export a PDF file to a DOCX file (apply OCR on the PDF file)
The sample below converts a PDF file into a number of supported formats such as:
- Microsoft Office file formats
- Text files
OCR processing is also performed on the input PDF file to extract text from images in the document.
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.exportpdf.ExportPDFToDOCXWithOCROption45public class ExportPDFToDOCXWithOCROption {67 // Initialize the logger.8 private static final Logger LOGGER = LoggerFactory.getLogger(ExportPDFToDOCXWithOCROption.class);910 public static void main(String[] args) {1112 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/exportPDFInput.pdf").toPath())) {13 // Initial setup, create credentials instance14 Credentials credentials = new ServicePrincipalCredentials(15 System.getenv("PDF_SERVICES_CLIENT_ID"),16 System.getenv("PDF_SERVICES_CLIENT_SECRET"));1718 // Creates a PDF Services instance19 PDFServices pdfServices = new PDFServices(credentials);2021 // Creates an asset(s) from source file(s) and upload22 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());2324 // Create parameters for the job25 ExportPDFParams exportPDFParams = ExportPDFParams.exportPDFParamsBuilder(ExportPDFTargetFormat.DOCX)26 .withExportOCRLocale(ExportOCRLocale.EN_US)27 .build();2829 // Creates a new job instance30 ExportPDFJob exportPDFJob = new ExportPDFJob(asset, exportPDFParams);3132 // Submit the job and gets the job result33 String location = pdfServices.submit(exportPDFJob);34 PDFServicesResponse<ExportPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, ExportPDFResult.class);3536 // Get content from the resulting asset(s)37 Asset resultAsset = pdfServicesResponse.getResult().getAsset();38 StreamAsset streamAsset = pdfServices.getContent(resultAsset);3940 // Creates an output stream and copy stream asset's content to it41 Files.createDirectories(Paths.get("output/"));42 OutputStream outputStream = Files.newOutputStream(new File("output/exportPDFWithOCROptionsOutput.docx").toPath());43 LOGGER.info("Saving asset at output/exportPDFWithOCROptionsOutput.docx");44 IOUtils.copy(streamAsset.getInputStream(), outputStream);45 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {46 LOGGER.error("Exception encountered while executing operation", ex);47 }48 }49}
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 ExportPDFToDocxWithOCROption.csproj56 namespace ExportPDFToDocxWithOCROption7 {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 and create a new operation instance.24 ExecutionContext executionContext = ExecutionContext.Create(credentials);25 ExportPDFOperation exportPdfOperation = ExportPDFOperation.CreateNew(ExportPDFTargetFormat.DOCX);2627 // Set operation input from a local PDF file28 FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"exportPdfInput.pdf");29 exportPdfOperation.SetInput(sourceFileRef);3031 // Create a new ExportPDFOptions instance from the specified OCR locale and set it into the operation.32 ExportPDFOptions exportPdfOptions = new ExportPDFOptions(ExportOCRLocale.EN_US);33 exportPdfOperation.SetOptions(exportPdfOptions);3435 // Execute the operation.36 FileRef result = exportPdfOperation.Execute(executionContext);3738 // Save the result to the specified location.39 result.SaveAs(Directory.GetCurrentDirectory() + "/output/ExportPDFToDOCXWithOCROption.docx");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-docx-to-pdf-with-ocr-options.js45const {6 ServicePrincipalCredentials,7 PDFServices,8 MimeType,9 ExportPDFParams,10 ExportPDFTargetFormat,11 ExportOCRLocale,12 ExportPDFJob,13 ExportPDFResult,14 SDKError,15 ServiceUsageError,16 ServiceApiError17} = require("@adobe/pdfservices-node-sdk");18const fs = require("fs");1920(async () => {21 let readStream;22 try {23 // Initial setup, create credentials instance24 const credentials = new ServicePrincipalCredentials({25 clientId: process.env.PDF_SERVICES_CLIENT_ID,26 clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET27 });2829 // Creates a PDF Services instance30 const pdfServices = new PDFServices({credentials});3132 // Creates an asset(s) from source file(s) and upload33 readStream = fs.createReadStream("./exportPDFInput.pdf");34 const inputAsset = await pdfServices.upload({35 readStream,36 mimeType: MimeType.PDF37 });3839 // Create parameters for the job40 const params = new ExportPDFParams({41 targetFormat: ExportPDFTargetFormat.DOCX,42 ocrLocale: ExportOCRLocale.EN_US43 });4445 // Creates a new job instance46 const job = new ExportPDFJob({inputAsset, params});4748 // Submit the job and get the job result49 const pollingURL = await pdfServices.submit({job});50 const pdfServicesResponse = await pdfServices.getJobResult({51 pollingURL,52 resultType: ExportPDFResult53 });5455 // Get content from the resulting asset(s)56 const resultAsset = pdfServicesResponse.result.asset;57 const streamAsset = await pdfServices.getContent({asset: resultAsset});5859 // Creates an output stream and copy stream asset's content to it60 const outputFilePath = "./ExportPDFToDOCXWithOCROption.docx";61 console.log(`Saving asset at ${outputFilePath}`);6263 const outputStream = fs.createWriteStream(outputFilePath);64 streamAsset.readStream.pipe(outputStream);65 } catch (err) {66 if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {67 console.log("Exception encountered while executing operation", err);68 } else {69 console.log("Exception encountered while executing operation", err);70 }71 }72})();
Copied to your clipboard1// Please refer our REST API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/Export-PDF34curl --location --request POST 'https://pdf-services.adobe.io/operation/exportpdf' \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 "targetFormat": "docx",11 "ocrLang": "en-US"12}'
Export a PDF to images
The sample below converts a PDF file's pages to a list of JPEG images. 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".
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.exportpdftoimages.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 (InputStream inputStream = Files.newInputStream(new File("src/main/resources/exportPDFToImageInput.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 ExportPDFToImagesParams exportPDFToImagesParams = ExportPDFToImagesParams.exportPDFToImagesParamsBuilder(25 ExportPDFToImagesTargetFormat.JPEG, ExportPDFToImagesOutputType.LIST_OF_PAGE_IMAGES).build();2627 // Creates a new job instance28 ExportPDFToImagesJob exportPDFToImagesJob = new ExportPDFToImagesJob(asset, exportPDFToImagesParams);2930 // Submit the job and gets the job result31 String location = pdfServices.submit(exportPDFToImagesJob);32 PDFServicesResponse<ExportPDFToImagesResult> pdfServicesResponse = pdfServices.getJobResult(location, ExportPDFToImagesResult.class);3334 // Get content from the resulting asset(s)35 List<Asset> resultAssets = pdfServicesResponse.getResult().getAssets();3637 Files.createDirectories(Paths.get("output/"));38 int index = 0;39 for(Asset resultAsset : resultAssets) {40 StreamAsset streamAsset = pdfServices.getContent(resultAsset);4142 // Creates an output stream and copy stream asset's content to it43 OutputStream outputStream = Files.newOutputStream(new File("output/exportPDFToImagesOutput_" + index + ".jpeg").toPath());44 LOGGER.info("Saving asset at output/exportPDFToImagesOutput_" + index + ".jpeg");45 IOUtils.copy(streamAsset.getInputStream(), outputStream);46 index++;47 }48 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {49 LOGGER.error("Exception encountered while executing operation", ex);50 }51 }52 }53
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd ExportPDFToJPEG/4// dotnet run ExportPDFToJPEG.csproj56 namespace ExportPDFToJPEG7 {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 and create a new operation instance.24 ExecutionContext executionContext = ExecutionContext.Create(credentials);25 ExportPDFOperation exportPdfOperation = ExportPDFOperation.CreateNew(ExportPDFTargetFormat.JPEG);2627 // Set operation input from a source file.28 FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"exportPdfToImageInput.pdf");29 exportPdfOperation.SetInput(sourceFileRef);3031 // Execute the operation.32 List<FileRef> result = exportPDFToImagesOperation.Execute(executionContext);3334 // Save the result to the specified location.35 int index = 0;36 foreach (FileRef fileRef in result)37 {38 fileRef.SaveAs(Directory.GetCurrentDirectory() + "/output/exportPDFToImagesOutput_" + index + ".jpeg");39 index++;40 }41 }4243 catch (ServiceUsageException ex)44 {45 log.Error("Exception encountered while executing operation", ex);46 }47 // Catch more errors here. . .48 }4950 static void ConfigureLogging()51 {52 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());53 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));54 }55 }56 }
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/exportpdftoimages/export-pdf-to-jpeg.js45const {6 ServicePrincipalCredentials,7 PDFServices,8 MimeType,9 ExportPDFToImagesJob,10 ExportPDFToImagesTargetFormat,11 ExportPDFToImagesOutputType,12 ExportPDFToImagesParams,13 ExportPDFToImagesResult,14 SDKError,15 ServiceUsageError,16 ServiceApiError17} = require("@adobe/pdfservices-node-sdk");18const fs = require("fs");1920(async () => {21 let readStream;22 try {23 // Initial setup, create credentials instance24 const credentials = new ServicePrincipalCredentials({25 clientId: process.env.PDF_SERVICES_CLIENT_ID,26 clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET27 });2829 // Creates a PDF Services instance30 const pdfServices = new PDFServices({credentials});3132 // Creates an asset(s) from source file(s) and upload33 readStream = fs.createReadStream("./exportPDFToImageInput.pdf");34 const inputAsset = await pdfServices.upload({35 readStream,36 mimeType: MimeType.PDF37 });3839 // Create parameters for the job40 const params = new ExportPDFToImagesParams({41 targetFormat: ExportPDFToImagesTargetFormat.JPEG,42 outputType: ExportPDFToImagesOutputType.LIST_OF_PAGE_IMAGES43 });4445 // Creates a new job instance46 const job = new ExportPDFToImagesJob({inputAsset, params});4748 // Submit the job and get the job result49 const pollingURL = await pdfServices.submit({job});50 const pdfServicesResponse = await pdfServices.getJobResult({51 pollingURL,52 resultType: ExportPDFToImagesResult53 });5455 // Get content from the resulting asset(s)56 const resultAssets = pdfServicesResponse.result.assets;5758 for (let i = 0; i < resultAssets.length; i++) {59 const _outputFilePath = "./exportPDFToImageOutput_${i}.jpeg";60 console.log(`Saving asset at ${_outputFilePath}`);6162 const streamAsset = await pdfServices.getContent({asset: resultAssets[i]});6364 // Creates an output stream and copy stream asset's content to it65 const outputStream = fs.createWriteStream(_outputFilePath);66 streamAsset.readStream.pipe(outputStream);67 }68 } catch (err) {69 if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {70 console.log("Exception encountered while executing operation", err);71 } else {72 console.log("Exception encountered while executing operation", err);73 }74 } finally {75 readStream?.destroy();76 }77})();
Copied to your clipboard1// Please refer our REST API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/PDF-To-Images34curl --location --request POST 'https://pdf-services.adobe.io/operation/pdftoimages' \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 "targetFormat": "jpeg",11 "outputType": "listOfPageImages"12}'
Export a PDF to zip of page images
The sample below converts a PDF file to one or more jpeg or png images. The resulting file is a ZIP archive containing one image per page of the source PDF 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.exportpdftoimages.ExportPDFToJPEGZip45 public class ExportPDFToJPEGZip {67 // Initialize the logger.8 private static final Logger LOGGER = LoggerFactory.getLogger(ExportPDFToJPEGZip.class);910 public static void main(String[] args) {11 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/exportPDFToImagesInput.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 ExportPDFToImagesParams exportPDFToImagesParams = ExportPDFToImagesParams.exportPDFToImagesParamsBuilder(25 ExportPDFToImagesTargetFormat.JPEG, ExportPDFToImagesOutputType.ZIP_OF_PAGE_IMAGES).build();2627 // Creates a new job instance28 ExportPDFToImagesJob exportPDFToImagesJob = new ExportPDFToImagesJob(asset, exportPDFToImagesParams);2930 // Submit the job and gets the job result31 String location = pdfServices.submit(exportPDFToImagesJob);32 PDFServicesResponse<ExportPDFToImagesResult> pdfServicesResponse = pdfServices.getJobResult(location, ExportPDFToImagesResult.class);3334 // Get content from the resulting asset(s)35 List<Asset> resultAssets = pdfServicesResponse.getResult().getAssets();36 StreamAsset streamAsset = pdfServices.getContent(resultAssets.get(0));3738 LOGGER.info("Media type of the received asset is "+ streamAsset.getMimeType());3940 // Creates an output stream and copy stream asset's content to it41 Files.createDirectories(Paths.get("output/"));42 OutputStream outputStream = Files.newOutputStream(new File("output/exportPDFToJPEGOutput.zip").toPath());43 LOGGER.info("Saving asset at output/exportPDFToJPEGOutput.zip");44 IOUtils.copy(streamAsset.getInputStream(), outputStream);45 } catch (ServiceApiException | IOException | SDKException | ServiceUsageException ex) {46 LOGGER.error("Exception encountered while executing operation", ex);47 }48 }49 }
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd ExportPDFToJPEGZip/4// dotnet run ExportPDFToJPEGZip.csproj56namespace7{8 class Program ExportPDFToJPEGZip9 {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 and create a new operation instance.24 ExecutionContext executionContext = ExecutionContext.Create(credentials);25 ExportPDFToImagesOperation exportPDFToImagesOperation = ExportPDFToImagesOperation.CreateNew(ExportPDFToImagesTargetFormat.JPEG);2627 // Set operation input from a source file.28 FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"exportPDFToImagesInput.pdf");29 exportPDFToImagesOperation.SetInput(sourceFileRef);3031 // Set the output type to create zip of images.32 exportPDFToImagesOperation.SetOutputType(ExportPDFToImagesOutputType.ZIP_OF_IMAGES);3334 // Execute the operation.35 List<FileRef> result = exportPDFToImagesOperation.Execute(executionContext);3637 // Save the result to the specified location.38 results[0].SaveAs(Directory.GetCurrentDirectory() + "/output/exportPDFToJPEGOutput.zip");39 }40 catch (ServiceUsageException ex)41 {42 log.Error("Exception encountered while executing operation", ex);43 }44 // Catch more errors here. . .45 }4647 static void ConfigureLogging()48 {49 ILoggerRepository logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());50 XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));51 }52 }53}
Copied to your clipboard1// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample2// Run the sample:3// node src/exportpdftoimages/export-pdf-to-jpeg-zip.js45const {6 ServicePrincipalCredentials,7 PDFServices,8 MimeType,9 ExportPDFToImagesParams,10 ExportPDFToImagesTargetFormat,11 ExportPDFToImagesOutputType,12 ExportPDFToImagesJob,13 ExportPDFToImagesResult,14 SDKError,15 ServiceUsageError,16 ServiceApiError17} = require("@adobe/pdfservices-node-sdk");18const fs = require("fs");1920(async () => {21 let readStream;22 try {23 // Initial setup, create credentials instance24 const credentials = new ServicePrincipalCredentials({25 clientId: process.env.PDF_SERVICES_CLIENT_ID,26 clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET27 });2829 // Creates a PDF Services instance30 const pdfServices = new PDFServices({credentials});3132 // Creates an asset(s) from source file(s) and upload33 readStream = fs.createReadStream("./exportPDFToImageInput.pdf");34 const inputAsset = await pdfServices.upload({35 readStream,36 mimeType: MimeType.PDF37 });3839 // Create parameters for the job40 const params = new ExportPDFToImagesParams({41 targetFormat: ExportPDFToImagesTargetFormat.JPEG,42 outputType: ExportPDFToImagesOutputType.ZIP_OF_PAGE_IMAGES43 });4445 // Creates a new job instance46 const job = new ExportPDFToImagesJob({inputAsset, params});4748 // Submit the job and get the job result49 const pollingURL = await pdfServices.submit({job});50 const pdfServicesResponse = await pdfServices.getJobResult({51 pollingURL,52 resultType: ExportPDFToImagesResult53 });5455 // Get content from the resulting asset(s)56 const resultAsset = pdfServicesResponse.result.assets;57 const streamAsset = await pdfServices.getContent({asset: resultAsset[0]});5859 // Creates an output stream and copy stream asset's content to it60 const outputFilePath = "./exportPDFToJPEGOutput.zip";61 console.log(`Saving asset at ${outputFilePath}`);6263 const outputStream = fs.createWriteStream(outputFilePath);64 streamAsset.readStream.pipe(outputStream);65 } catch (err) {66 if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {67 console.log("Exception encountered while executing operation", err);68 } else {69 console.log("Exception encountered while executing operation", err);70 }71 } finally {72 readStream?.destroy();73 }74})();
Copied to your clipboard1// Please refer our REST API docs for more information2// https://developer.adobe.com/document-services/docs/apis/#tag/PDF-To-Images34curl --location --request POST 'https://pdf-services.adobe.io/operation/pdftoimages' \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 "targetFormat": "jpeg",11 "outputType": "zipOfPageImages"12}'