Edit in GitHubLog an issue

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
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 {
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);
20
21 // Set operation input from a local PDF file
22 FileRef sourceFileRef = FileRef.createFromLocalFile("src/main/resources/exportPDFInput.pdf");
23 exportPdfOperation.setInput(sourceFileRef);
24
25 // Execute the operation.
26 FileRef result = exportPdfOperation.execute(executionContext);
27
28 // Save the result to the specified location.
29 result.saveAs("output/exportPdfOutput.docx");
30
31 } catch (ServiceApiException | IOException | SdkException | ServiceUsageException ex) {
32 LOGGER.error("Exception encountered while executing operation", ex);
33 }
34 }
35 }
36

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".

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.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 {
12
13 // Initial setup, create credentials instance.
14 Credentials credentials = Credentials.serviceAccountCredentialsBuilder()
15 .fromFile("pdfservices-api-credentials.json")
16 .build();
17
18 //Create an ExecutionContext using credentials and create a new operation instance.
19 ExecutionContext executionContext = ExecutionContext.create(credentials);
20 ExportPDFOperation exportPdfOperation = ExportPDFOperation.createNew(ExportPDFTargetFormat.JPEG);
21
22 // Set operation input from a source file.
23 FileRef sourceFileRef = FileRef.createFromLocalFile("src/main/resources/exportPDFToImageInput.pdf");
24 exportPdfOperation.setInput(sourceFileRef);
25
26 // Execute the operation.
27 FileRef result = exportPdfOperation.execute(executionContext);
28
29 // Save the result to the specified location.
30 result.saveAs("output/exportPDFToJPEG.zip");
31
32 } catch (ServiceApiException | IOException | SdkException | ServiceUsageException ex) {
33 LOGGER.error("Exception encountered while executing operation", ex);
34 }
35 }
36 }
37

Export a PDF to list of images#

The sample below converts a PDF file to one or more jpeg or png images.

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.ExportPDFToJPEGList
4
5 public class ExportPDFToJPEGList {
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 {
12
13 // Initial setup, create credentials instance.
14 Credentials credentials = Credentials.serviceAccountCredentialsBuilder()
15 .fromFile("pdfservices-api-credentials.json")
16 .build();
17
18 //Create an ExecutionContext using credentials and create a new operation instance.
19 ExecutionContext executionContext = ExecutionContext.create(credentials);
20 ExportPDFToImagesOperation exportPDFToImagesOperation = ExportPDFToImagesOperation.createNew(ExportPDFToImagesTargetFormat.JPEG);
21
22 // Set operation input from a source file.
23 FileRef sourceFileRef = FileRef.createFromLocalFile("src/main/resources/exportPDFToImageInput.pdf");
24 exportPDFToImagesOperation.setInput(sourceFileRef);
25
26 // Execute the operation.
27 List<FileRef> results = exportPDFToImagesOperation.execute(executionContext);
28
29 // 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 }
Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.