Get PDF Properties
Get PDF Properties as a JSON File
The sample below fetches the properties of an input PDF, as a JSON file.
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.pdfproperties.PDFPropertiesAsFile45 public class PDFPropertiesAsFile {67 // Initialize the logger.8 private static final Logger LOGGER = LoggerFactory.getLogger(PDFPropertiesAsFile.class);910 public static void main(String[] args) {1112 try {1314 // Initial setup, create credentials instance.15 Credentials credentials = Credentials.serviceAccountCredentialsBuilder()16 .fromFile("pdfservices-api-credentials.json")17 .build();1819 //Create an ExecutionContext using credentials and create a new operation instance.20 ExecutionContext executionContext = ExecutionContext.create(credentials);21 PDFPropertiesOperation pdfPropertiesOperation = PDFPropertiesOperation.createNew();2223 // Provide an input FileRef for the operation24 FileRef source = FileRef.createFromLocalFile("src/main/resources/pdfPropertiesInput.pdf");25 pdfPropertiesOperation.setInputFile(source);2627 // Execute the operation28 FileRef result = pdfPropertiesOperation.executeAndReturnFileRef(executionContext);2930 // Save the result at the specified location31 result.saveAs("output/pdfPropertiesOutput.json");3233 } catch (ServiceApiException | IOException | SdkException | ServiceUsageException ex) {34 LOGGER.error("Exception encountered while executing operation", ex);35 }36 }37 }38
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd PDFPropertiesAsFile/4// dotnet run PDFPropertiesAsFile.csproj56namespace PDFPropertiesAsFile7{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 PDFPropertiesOperation pdfPropertiesOperation = PDFPropertiesOperation.CreateNew();2526 // Provide an input FileRef for the operation27 FileRef source = FileRef.CreateFromLocalFile(@"pdfPropertiesInput.pdf");28 pdfPropertiesOperation.SetInput(source);2930 // Execute the operation.31 FileRef result = pdfPropertiesOperation.ExecuteAndReturnFileRef(executionContext);3233 // Save the result to the specified location.34 result.SaveAs(Directory.GetCurrentDirectory() + "/output/pdfPropertiesOutput.json");3536 }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/pdf-properties-as-file.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 clientContext = PDFServicesSdk.ExecutionContext.create(credentials),16 pdfPropertiesOperation = PDFServicesSdk.PDFProperties.Operation.createNew();1718 // Set operation input from a source file.19 const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/pdfPropertiesInput.pdf');20 pdfPropertiesOperation.setInput(input);2122 // Execute the operation and Save the result to the specified location.23 pdfPropertiesOperation.executeAndReturnFileRef(clientContext)24 .then(result => result.saveAsFile('output/PDFPropertiesOutput.json'))25 .catch(err => {26 if(err instanceof PDFServicesSdk.Error.ServiceApiError27 || err instanceof PDFServicesSdk.Error.ServiceUsageError) {28 console.log('Exception encountered while executing operation', err);29 } else {30 console.log('Exception encountered while executing operation', err);31 }32 });33} catch (err) {34 console.log('Exception encountered while executing operation', err);35}
Copied to your clipboard1// Please refer our REST API docs for more information2// https://documentcloud.adobe.com/document-services/index.html#post-pdfProperties34curl --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 \"pageLevel\": true14 }15 },16 \"documentIn\": {17 \"cpf:location\": \"InputFile0\",18 \"dc:format\": \"application/pdf\"19 }20 },21 \"cpf:engine\": {22 \"repo:assetId\": \"urn:aaid:cpf:Service-fd9b06fe2f164df7975254581d6ab00e\"23 },24 \"cpf:outputs\": {25 \"metadata\": {26 \"dc:format\": \"application/json\",27 \"cpf:location\": \"jsonoutput\"28 }29 }30}"' \31--form 'InputFile0=@"{{Placeholder for input file (absolute path)}}"'
Get PDF Properties as a JSON Object
The sample below fetches the properties of an input PDF, as a JSON object.
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.pdfproperties.PDFPropertiesAsJSONObject45 public class PDFPropertiesAsJSONObject {67 // Initialize the logger.8 private static final Logger LOGGER = LoggerFactory.getLogger(PDFPropertiesAsJSONObject.class);910 public static void main(String[] args) {1112 try {1314 // Initial setup, create credentials instance.15 Credentials credentials = Credentials.serviceAccountCredentialsBuilder()16 .fromFile("pdfservices-api-credentials.json")17 .build();1819 //Create an ExecutionContext using credentials and create a new operation instance.20 ExecutionContext executionContext = ExecutionContext.create(credentials);21 PDFPropertiesOperation pdfPropertiesOperation = PDFPropertiesOperation.createNew();2223 // Provide an input FileRef for the operation24 FileRef source = FileRef.createFromLocalFile("src/main/resources/pdfPropertiesInput.pdf");25 pdfPropertiesOperation.setInputFile(source);2627 // Build PDF Properties options to include page level properties and set them into the operation28 PDFPropertiesOptions pdfPropertiesOptions = PDFPropertiesOptions.PDFPropertiesOptionsBuilder()29 .includePageLevelProperties(true)30 .build();31 pdfPropertiesOperation.setOptions(pdfPropertiesOptions);3233 // Execute the operation and return JSON Object34 JSONObject result = pdfPropertiesOperation.execute(executionContext);35 LOGGER.info("The resultant PDF Properties are: {}", result);3637 } catch (ServiceApiException | IOException | SdkException | ServiceUsageException ex) {38 LOGGER.error("Exception encountered while executing operation", ex);39 }40 }41 }
Copied to your clipboard1// Get the samples from https://www.adobe.com/go/pdftoolsapi_net_samples2// Run the sample:3// cd PDFPropertiesAsJSONObject/4// dotnet run PDFPropertiesAsJSONObject.csproj56namespace PDFPropertiesAsJSONObject7{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 PDFPropertiesOperation pdfPropertiesOperation = PDFPropertiesOperation.CreateNew();2526 // Provide an input FileRef for the operation27 FileRef source = FileRef.CreateFromLocalFile(@"pdfPropertiesInput.pdf");28 pdfPropertiesOperation.SetInput(source);2930 // Build PDF Properties options to include page level properties and set them into the operation31 PDFPropertiesOptions pdfPropertiesOptions = PDFPropertiesOptions.PDFPropertiesOptionsBuilder()32 .IncludePageLevelProperties(true)33 .Build();34 pdfPropertiesOperation.SetOptions(pdfPropertiesOptions);3536 // Execute the operation and return JSON Object37 JObject result = pdfPropertiesOperation.Execute(executionContext);38 Console.WriteLine("The resultant PDF Properties are: " + result.ToString());3940 }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/pdf-properties-as-json.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 pdfPropertiesOperation = PDFServicesSdk.PDFProperties.Operation.createNew();1718 // Set operation input from a source file.19 const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/pdfPropertiesInput.pdf');20 pdfPropertiesOperation.setInput(input);2122 // Provide any custom configuration options for the operation.23 const options = new PDFServicesSdk.PDFProperties.options.PDFPropertiesOptions.Builder()24 .includePageLevelProperties(true)25 .build();26 pdfPropertiesOperation.setOptions(options);2728 // Execute the operation and log the JSON Object.29 pdfPropertiesOperation.execute(executionContext)30 .then(result => console.log("The resultant json object is : " + JSON.stringify(result)))31 .catch(err => {32 if(err instanceof PDFServicesSdk.Error.ServiceApiError33 || err instanceof PDFServicesSdk.Error.ServiceUsageError) {34 console.log('Exception encountered while executing operation', err);35 } else {36 console.log('Exception encountered while executing operation', err);37 }38 });39} catch (err) {40 console.log('Exception encountered while executing operation', err);41}
Copied to your clipboard1// Please refer our REST API docs for more information2// https://documentcloud.adobe.com/document-services/index.html#post-pdfProperties34curl --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 \"pageLevel\": true14 }15 },16 \"documentIn\": {17 \"cpf:location\": \"InputFile0\",18 \"dc:format\": \"application/pdf\"19 }20 },21 \"cpf:engine\": {22 \"repo:assetId\": \"urn:aaid:cpf:Service-fd9b06fe2f164df7975254581d6ab00e\"23 },24 \"cpf:outputs\": {25 \"metadata\": {26 \"dc:format\": \"application/json\",27 \"cpf:location\": \"jsonoutput\"28 }29 }30}"' \31--form 'InputFile0=@"{{Placeholder for input file (absolute path)}}"'