Edit in GitHubLog an issue

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 clipboard
1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples
2// Run the sample:
3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.exportpdf.ExportPDFToDOCX
4
5public class ExportPDFToDOCX {
6
7 // Initialize the logger.
8 private static final Logger LOGGER = LoggerFactory.getLogger(ExportPDFToDOCX.class);
9
10 public static void main(String[] args) {
11
12 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/exportPDFInput.pdf").toPath())) {
13 // Initial setup, create credentials instance
14 Credentials credentials = new ServicePrincipalCredentials(
15 System.getenv("PDF_SERVICES_CLIENT_ID"),
16 System.getenv("PDF_SERVICES_CLIENT_SECRET"));
17
18 // Creates a PDF Services instance
19 PDFServices pdfServices = new PDFServices(credentials);
20
21 // Creates an asset(s) from source file(s) and upload
22 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());
23
24 // Create parameters for the job
25 ExportPDFParams exportPDFParams = ExportPDFParams.exportPDFParamsBuilder(ExportPDFTargetFormat.DOCX)
26 .build();
27
28 // Creates a new job instance
29 ExportPDFJob exportPDFJob = new ExportPDFJob(asset, exportPDFParams);
30
31 // Submit the job and gets the job result
32 String location = pdfServices.submit(exportPDFJob);
33 PDFServicesResponse<ExportPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, ExportPDFResult.class);
34
35 // Get content from the resulting asset(s)
36 Asset resultAsset = pdfServicesResponse.getResult().getAsset();
37 StreamAsset streamAsset = pdfServices.getContent(resultAsset);
38
39 // Creates an output stream and copy stream asset's content to it
40 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

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 clipboard
1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples
2// Run the sample:
3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.exportpdf.ExportPDFToDOCXWithOCROption
4
5public class ExportPDFToDOCXWithOCROption {
6
7 // Initialize the logger.
8 private static final Logger LOGGER = LoggerFactory.getLogger(ExportPDFToDOCXWithOCROption.class);
9
10 public static void main(String[] args) {
11
12 try (InputStream inputStream = Files.newInputStream(new File("src/main/resources/exportPDFInput.pdf").toPath())) {
13 // Initial setup, create credentials instance
14 Credentials credentials = new ServicePrincipalCredentials(
15 System.getenv("PDF_SERVICES_CLIENT_ID"),
16 System.getenv("PDF_SERVICES_CLIENT_SECRET"));
17
18 // Creates a PDF Services instance
19 PDFServices pdfServices = new PDFServices(credentials);
20
21 // Creates an asset(s) from source file(s) and upload
22 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());
23
24 // Create parameters for the job
25 ExportPDFParams exportPDFParams = ExportPDFParams.exportPDFParamsBuilder(ExportPDFTargetFormat.DOCX)
26 .withExportOCRLocale(ExportOCRLocale.EN_US)
27 .build();
28
29 // Creates a new job instance
30 ExportPDFJob exportPDFJob = new ExportPDFJob(asset, exportPDFParams);
31
32 // Submit the job and gets the job result
33 String location = pdfServices.submit(exportPDFJob);
34 PDFServicesResponse<ExportPDFResult> pdfServicesResponse = pdfServices.getJobResult(location, ExportPDFResult.class);
35
36 // Get content from the resulting asset(s)
37 Asset resultAsset = pdfServicesResponse.getResult().getAsset();
38 StreamAsset streamAsset = pdfServices.getContent(resultAsset);
39
40 // Creates an output stream and copy stream asset's content to it
41 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}

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 clipboard
1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples
2// Run the sample:
3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.exportpdftoimages.ExportPDFToJPEG
4
5 public class ExportPDFToJPEG {
6
7 // Initialize the logger.
8 private static final Logger LOGGER = LoggerFactory.getLogger(ExportPDFToJPEG.class);
9
10 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 instance
13 Credentials credentials = new ServicePrincipalCredentials(
14 System.getenv("PDF_SERVICES_CLIENT_ID"),
15 System.getenv("PDF_SERVICES_CLIENT_SECRET"));
16
17 // Creates a PDF Services instance
18 PDFServices pdfServices = new PDFServices(credentials);
19
20 // Creates an asset(s) from source file(s) and upload
21 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());
22
23 // Create parameters for the job
24 ExportPDFToImagesParams exportPDFToImagesParams = ExportPDFToImagesParams.exportPDFToImagesParamsBuilder(
25 ExportPDFToImagesTargetFormat.JPEG, ExportPDFToImagesOutputType.LIST_OF_PAGE_IMAGES).build();
26
27 // Creates a new job instance
28 ExportPDFToImagesJob exportPDFToImagesJob = new ExportPDFToImagesJob(asset, exportPDFToImagesParams);
29
30 // Submit the job and gets the job result
31 String location = pdfServices.submit(exportPDFToImagesJob);
32 PDFServicesResponse<ExportPDFToImagesResult> pdfServicesResponse = pdfServices.getJobResult(location, ExportPDFToImagesResult.class);
33
34 // Get content from the resulting asset(s)
35 List<Asset> resultAssets = pdfServicesResponse.getResult().getAssets();
36
37 Files.createDirectories(Paths.get("output/"));
38 int index = 0;
39 for(Asset resultAsset : resultAssets) {
40 StreamAsset streamAsset = pdfServices.getContent(resultAsset);
41
42 // Creates an output stream and copy stream asset's content to it
43 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

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 clipboard
1// Get the samples from https://www.adobe.com/go/pdftoolsapi_java_samples
2// Run the sample:
3// mvn -f pom.xml exec:java -Dexec.mainClass=com.adobe.pdfservices.operation.samples.exportpdftoimages.ExportPDFToJPEGZip
4
5 public class ExportPDFToJPEGZip {
6
7 // Initialize the logger.
8 private static final Logger LOGGER = LoggerFactory.getLogger(ExportPDFToJPEGZip.class);
9
10 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 instance
13 Credentials credentials = new ServicePrincipalCredentials(
14 System.getenv("PDF_SERVICES_CLIENT_ID"),
15 System.getenv("PDF_SERVICES_CLIENT_SECRET"));
16
17 // Creates a PDF Services instance
18 PDFServices pdfServices = new PDFServices(credentials);
19
20 // Creates an asset(s) from source file(s) and upload
21 Asset asset = pdfServices.upload(inputStream, PDFServicesMediaType.PDF.getMediaType());
22
23 // Create parameters for the job
24 ExportPDFToImagesParams exportPDFToImagesParams = ExportPDFToImagesParams.exportPDFToImagesParamsBuilder(
25 ExportPDFToImagesTargetFormat.JPEG, ExportPDFToImagesOutputType.ZIP_OF_PAGE_IMAGES).build();
26
27 // Creates a new job instance
28 ExportPDFToImagesJob exportPDFToImagesJob = new ExportPDFToImagesJob(asset, exportPDFToImagesParams);
29
30 // Submit the job and gets the job result
31 String location = pdfServices.submit(exportPDFToImagesJob);
32 PDFServicesResponse<ExportPDFToImagesResult> pdfServicesResponse = pdfServices.getJobResult(location, ExportPDFToImagesResult.class);
33
34 // Get content from the resulting asset(s)
35 List<Asset> resultAssets = pdfServicesResponse.getResult().getAssets();
36 StreamAsset streamAsset = pdfServices.getContent(resultAssets.get(0));
37
38 LOGGER.info("Media type of the received asset is "+ streamAsset.getMimeType());
39
40 // Creates an output stream and copy stream asset's content to it
41 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 }
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.