Edit in GitHubLog an issue

Get PDF Properties

Get PDF Properties as a JSON File#

The sample below fetches the properties of an input PDF, as a JSON file.

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.pdfproperties.PDFPropertiesAsFile
4
5 public class PDFPropertiesAsFile {
6
7 // Initialize the logger.
8 private static final Logger LOGGER = LoggerFactory.getLogger(PDFPropertiesAsFile.class);
9
10 public static void main(String[] args) {
11
12 try {
13
14 // Initial setup, create credentials instance.
15 Credentials credentials = Credentials.serviceAccountCredentialsBuilder()
16 .fromFile("pdfservices-api-credentials.json")
17 .build();
18
19 //Create an ExecutionContext using credentials and create a new operation instance.
20 ExecutionContext executionContext = ExecutionContext.create(credentials);
21 PDFPropertiesOperation pdfPropertiesOperation = PDFPropertiesOperation.createNew();
22
23 // Provide an input FileRef for the operation
24 FileRef source = FileRef.createFromLocalFile("src/main/resources/pdfPropertiesInput.pdf");
25 pdfPropertiesOperation.setInputFile(source);
26
27 // Execute the operation
28 FileRef result = pdfPropertiesOperation.executeAndReturnFileRef(executionContext);
29
30 // Save the result at the specified location
31 result.saveAs("output/pdfPropertiesOutput.json");
32
33 } catch (ServiceApiException | IOException | SdkException | ServiceUsageException ex) {
34 LOGGER.error("Exception encountered while executing operation", ex);
35 }
36 }
37 }
38

Get PDF Properties as a JSON Object#

The sample below fetches the properties of an input PDF, as a JSON object.

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.pdfproperties.PDFPropertiesAsJSONObject
4
5 public class PDFPropertiesAsJSONObject {
6
7 // Initialize the logger.
8 private static final Logger LOGGER = LoggerFactory.getLogger(PDFPropertiesAsJSONObject.class);
9
10 public static void main(String[] args) {
11
12 try {
13
14 // Initial setup, create credentials instance.
15 Credentials credentials = Credentials.serviceAccountCredentialsBuilder()
16 .fromFile("pdfservices-api-credentials.json")
17 .build();
18
19 //Create an ExecutionContext using credentials and create a new operation instance.
20 ExecutionContext executionContext = ExecutionContext.create(credentials);
21 PDFPropertiesOperation pdfPropertiesOperation = PDFPropertiesOperation.createNew();
22
23 // Provide an input FileRef for the operation
24 FileRef source = FileRef.createFromLocalFile("src/main/resources/pdfPropertiesInput.pdf");
25 pdfPropertiesOperation.setInputFile(source);
26
27 // Build PDF Properties options to include page level properties and set them into the operation
28 PDFPropertiesOptions pdfPropertiesOptions = PDFPropertiesOptions.PDFPropertiesOptionsBuilder()
29 .includePageLevelProperties(true)
30 .build();
31 pdfPropertiesOperation.setOptions(pdfPropertiesOptions);
32
33 // Execute the operation and return JSON Object
34 JSONObject result = pdfPropertiesOperation.execute(executionContext);
35 LOGGER.info("The resultant PDF Properties are: {}", result);
36
37 } catch (ServiceApiException | IOException | SdkException | ServiceUsageException ex) {
38 LOGGER.error("Exception encountered while executing operation", ex);
39 }
40 }
41 }
Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.