";
+```javascript
+// Create parameters for the job
+const params = new PDFElectronicSealParams({
+ documentLevelPermission
+ certificateCredentials,
+ sealFieldOptions,
+ sealAppearanceOptions
+});
+
+// Creates a new job instance
+const job = new PDFElectronicSealJob({
+ inputAsset: sourceFileAsset,
+ sealImageAsset,
+ params,
+});
+```
-//Create CSCAuthContext instance using access token and token type.
-cscAuthContext = new options.CSCAuthContext(accessToken, "Bearer");
+This set of code defines what we're doing (an Electronic Seal operation),
+it defines parameters for the seal job and sets input seal image asset.
-//Create CertificateCredentials instance with required certificate details.
-certificateCredentials = options.CertificateCredentials.cscCredentialBuilder()
- .withProviderName(providerName)
- .withCredentialID(credentialID)
- .withPin(pin)
- .withCSCAuthContext(cscAuthContext)
- .build();
+9) The next code block submits the job and gets the job result:
+```javascript
+// Submit the job and get the job result
+const pollingURL = await pdfServices.submit({job});
+const pdfServicesResponse = await pdfServices.getJobResult({
+ pollingURL,
+ resultType: PDFElectronicSealResult
+});
+
+// Get content from the resulting asset(s)
+const resultAsset = pdfServicesResponse.result.asset;
+const streamAsset = await pdfServices.getContent({asset: resultAsset});
```
-8) Now, let's create the seal options with certificate credentials and field options:
+10) The next code block saves the result at the specified location:
```javascript
- //Create SealOptions instance with sealing parameters.
-sealOptions = new options.SealOptions.Builder(certificateCredentials, fieldOptions)
- .withAppearanceOptions(appearanceOptions)
- .build()
-```
+// Creates a write stream and copy stream asset's content to it
+const outputFilePath = "./sealedOutput.pdf";
+console.log(`Saving asset at ${outputFilePath}`);
+const writeStream = fs.createWriteStream(outputFilePath);
+streamAsset.readStream.pipe(writeStream);
+```
-9) Now, let's create the operation:
+Here's the complete application (`electronic-seal.js`):
```javascript
-//Create the PDFElectronicSealOperation instance using the SealOptions instance
-const pdfElectronicSealOperation = pdfElectronicSeal.Operation.createNew(sealOptions);
+const {
+ ServicePrincipalCredentials,
+ PDFServices,
+ MimeType,
+ FieldLocation,
+ FieldOptions,
+ CSCAuthContext,
+ CSCCredential,
+ PDFElectronicSealParams,
+ PDFElectronicSealJob,
+ PDFElectronicSealResult,
+ AppearanceOptions,
+ AppearanceItem,
+ SDKError,
+ ServiceUsageError,
+ ServiceApiError, DocumentLevelPermission
+} = require("@adobe/pdfservices-node-sdk");
+const fs = require("fs");
+
+(async () => {
+
+ let sourceFileReadStream;
+ let sealImageReadStream;
+ try {
+ // Initial setup, create credentials instance
+ const credentials = new ServicePrincipalCredentials({
+ clientId: process.env.PDF_SERVICES_CLIENT_ID,
+ clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET
+ });
-//Set the input source file for PDFElectronicSealOperation instance
-pdfElectronicSealOperation.setInput(sourceFile);
+ // Creates a PDF Services instance
+ const pdfServices = new PDFServices({credentials});
+
+ // Creates an asset(s) from source file(s) and upload
+ sourceFileReadStream = fs.createReadStream("./sampleInvoice.pdf")
+ sealImageReadStream = fs.createReadStream("./sampleSealImage.png");
+ const [sourceFileAsset, sealImageAsset] = await pdfServices.uploadAssets({
+ streamAssets: [{
+ readStream: sourceFileReadStream,
+ mimeType: MimeType.PDF
+ }, {
+ readStream: sealImageReadStream,
+ mimeType: MimeType.PNG
+ }]
+ });
-//Set the optional input seal image for PDFElectronicSealOperation instance
-pdfElectronicSealOperation.setSealImage(sealImageFile);
+ // Set the document level permission to be applied for output document
+ const documentLevelPermission = DocumentLevelPermission.FORM_FILLING;
+
+ // Create AppearanceOptions and add the required signature appearance items
+ const sealAppearanceOptions = new AppearanceOptions({
+ items: [
+ AppearanceItem.DATE,
+ AppearanceItem.SEAL_IMAGE,
+ AppearanceItem.NAME,
+ AppearanceItem.LABELS,
+ AppearanceItem.DISTINGUISHED_NAME
+ ]
+ });
-```
-This code creates a seal operation using sealOptions, input source file and input seal image.
+ // Set the Seal Field Name to be created in input PDF document
+ const sealFieldName = "Signature1";
-10) Let's execute this seal operation:
+ // Set the page number in input document for applying seal
+ const sealPageNumber = 1;
-```javascript
-// Execute the operation and Save the result to the specified location.
-pdfElectronicSealOperation.execute(executionContext)
- .then(result => result.saveAsFile("output/sealedOutput.pdf"))
- .catch(err => {
- if(err instanceof PDFServicesSdk.Error.ServiceApiError
- || err instanceof PDFServicesSdk.Error.ServiceUsageError) {
- console.log('Exception encountered while executing operation', err);
- } else {
- console.log('Exception encountered while executing operation', err);
- }
+ // Set if seal should be visible or invisible
+ const sealVisible = true;
+
+ // Create FieldLocation instance and set the coordinates for applying signature
+ const fieldLocation = new FieldLocation({
+ left: 150,
+ top: 250,
+ right: 350,
+ bottom: 200
});
-```
-Here's the complete application (`electronic-seal.js`):
+ // Create FieldOptions instance with required details
+ const sealFieldOptions = new FieldOptions({
+ visible: sealVisible,
+ location: fieldLocation,
+ fieldName: sealFieldName,
+ pageNumber: sealPageNumber,
+ });
-```javascript
-/*
- * Copyright 2023 Adobe
- * All Rights Reserved.
- *
- * NOTICE: Adobe permits you to use, modify, and distribute this file in
- * accordance with the terms of the Adobe license agreement accompanying
- * it. If you have received this file from a source other than Adobe,
- * then your use, modification, or distribution of it requires the prior
- * written permission of Adobe.
- */
-
-const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');
-
-/**
- * This sample illustrates how to apply electronic seal over the PDF document using custom appearance options.
- *
- *
- * To know more about PDF Electronic Seal, please see the <documentation.
- *
- * Refer to README.md for instructions on how to run the samples.
- */
-try {
- // Initial setup, create credentials instance.
- const credentials = PDFServicesSdk.Credentials
- .servicePrincipalCredentialsBuilder()
- .withClientId(process.env.PDF_SERVICES_CLIENT_ID)
- .withClientSecret(process.env.PDF_SERVICES_CLIENT_SECRET)
- .build();
-
- // Create an ExecutionContext using credentials
- const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);
-
- const pdfElectronicSeal = PDFServicesSdk.PDFElectronicSeal,
- options = pdfElectronicSeal.options;
-
- //Get the input document to perform the sealing operation
- const sourceFile = PDFServicesSdk.FileRef.createFromLocalFile('./sampleInvoice.pdf'),
-
- //Get the background seal image for signature , if required.
- sealImageFile = PDFServicesSdk.FileRef.createFromLocalFile('./sampleSealImage.png');
-
- //Create AppearanceOptions and add the required signature appearance items
- appearanceOptions = new options.AppearanceOptions();
- appearanceOptions.addItem(options.AppearanceOptions.AppearanceItem.DATE);
- appearanceOptions.addItem(options.AppearanceOptions.AppearanceItem.SEAL_IMAGE);
- appearanceOptions.addItem(options.AppearanceOptions.AppearanceItem.NAME);
- appearanceOptions.addItem(options.AppearanceOptions.AppearanceItem.LABELS);
- appearanceOptions.addItem(options.AppearanceOptions.AppearanceItem.DISTINGUISHED_NAME);
-
- // Set the Seal Field Name to be created in input PDF document.
- sealFieldName = "Signature1";
-
- // Set the page number in input document for applying seal.
- sealPageNumber = 1;
-
- // Set if seal should be visible or invisible.
- sealVisible = true;
-
- //Create FieldLocation instance and set the coordinates for applying signature
- fieldLocation = new options.FieldLocation(150,250,350,200);
-
- //Create FieldOptions instance with required details.
- fieldOptions = new options.FieldOptions.Builder(sealFieldName)
- .setFieldLocation(fieldLocation)
- .setPageNumber(sealPageNumber)
- .setVisible(sealVisible)
- .build();
-
- //Set the name of TSP Provider being used.
- providerName = "";
-
- //Set the access token to be used to access TSP provider hosted APIs.
- accessToken = "";
-
- //Set the credential ID.
- credentialID = "";
-
- //Set the PIN generated while creating credentials.
- pin = "";
-
- //Create CSCAuthContext instance using access token and token type.
- cscAuthContext = new options.CSCAuthContext(accessToken, "Bearer");
-
- //Create CertificateCredentials instance with required certificate details.
- certificateCredentials = options.CertificateCredentials.cscCredentialBuilder()
- .withProviderName(providerName)
- .withCredentialID(credentialID)
- .withPin(pin)
- .withCSCAuthContext(cscAuthContext)
- .build();
-
- //Create SealOptions instance with sealing parameters.
- sealOptions = new options.SealOptions.Builder(certificateCredentials, fieldOptions)
- .withAppearanceOptions(appearanceOptions)
- .build()
-
- //Create the PDFElectronicSealOperation instance using the SealOptions instance
- const pdfElectronicSealOperation = pdfElectronicSeal.Operation.createNew(sealOptions);
-
- //Set the input source file for PDFElectronicSealOperation instance
- pdfElectronicSealOperation.setInput(sourceFile);
-
- //Set the optional input seal image for PDFElectronicSealOperation instance
- pdfElectronicSealOperation.setSealImage(sealImageFile);
-
- // Execute the operation and Save the result to the specified location.
- pdfElectronicSealOperation.execute(executionContext)
- .then(result => result.saveAsFile("output/sealedOutput.pdf"))
- .catch(err => {
- if(err instanceof PDFServicesSdk.Error.ServiceApiError
- || err instanceof PDFServicesSdk.Error.ServiceUsageError) {
- console.log('Exception encountered while executing operation', err);
- } else {
- console.log('Exception encountered while executing operation', err);
- }
- });
-
-} catch (err) {
- console.log('Exception encountered while executing operation', err);
-}
+ // Set the name of TSP Provider being used
+ const providerName = "";
+
+ // Set the access token to be used to access TSP provider hosted APIs
+ const accessToken = "";
+
+ // Set the credential ID
+ const credentialId = "";
+
+ // Set the PIN generated while creating credentials
+ const pin = "";
+
+ // Create CSCAuthContext instance using access token and token type
+ const authorizationContext = new CSCAuthContext({
+ accessToken,
+ tokenType: "Bearer"
+ });
+
+ // Create CertificateCredentials instance with required certificate details
+ const certificateCredentials = new CSCCredential({
+ providerName,
+ credentialId,
+ pin,
+ authorizationContext,
+ });
+
+ // Create parameters for the job
+ const params = new PDFElectronicSealParams({
+ documentLevelPermission
+ certificateCredentials,
+ sealFieldOptions,
+ sealAppearanceOptions
+ });
+
+ // Creates a new job instance
+ const job = new PDFElectronicSealJob({
+ inputAsset: sourceFileAsset,
+ sealImageAsset,
+ params,
+ });
+
+ // Submit the job and get the job result
+ const pollingURL = await pdfServices.submit({job});
+ const pdfServicesResponse = await pdfServices.getJobResult({
+ pollingURL,
+ resultType: PDFElectronicSealResult
+ });
+ // Get content from the resulting asset(s)
+ const resultAsset = pdfServicesResponse.result.asset;
+ const streamAsset = await pdfServices.getContent({asset: resultAsset});
+
+ // Creates a write stream and copy stream asset's content to it
+ const outputFilePath = "./sealedOutput.pdf";
+ console.log(`Saving asset at ${outputFilePath}`);
+
+ const writeStream = fs.createWriteStream(outputFilePath);
+ streamAsset.readStream.pipe(writeStream);
+ } catch (err) {
+ if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {
+ console.log("Exception encountered while executing operation", err);
+ } else {
+ console.log("Exception encountered while executing operation", err);
+ }
+ } finally {
+ sourceFileReadStream?.destroy();
+ sealImageReadStream?.destroy();
+ }
+})();
```
## Next Steps
diff --git a/src/pages/overview/pdf-extract-api/gettingstarted.md b/src/pages/overview/pdf-extract-api/gettingstarted.md
index c8c64521e..302bd261f 100644
--- a/src/pages/overview/pdf-extract-api/gettingstarted.md
+++ b/src/pages/overview/pdf-extract-api/gettingstarted.md
@@ -5,7 +5,7 @@ title: Getting Started | PDF Accessibility Auto-Tag API | Adobe PDF Services
# Getting Started
-PDF Accessibility Auto-Tag API assists in the process of improving accessibility in individual PDFs via auto-tagging, adding document structure tags to the PDF file that are used to read a document's text and presenting it in a way that makes sense to users using assistive technology. The API is accessible through SDKs which help you get up and running quickly. Once you've received your developer credential, download and set up one of the sample projects. After you're familiar with the APIs, leverage the samples in your own server-side code.
+The PDF Extract API provides modern cloud-based capabilities for automatically extracting contents from PDF. The API is accessible through SDKs which help you get up and running quickly. Once you've received your developer credential, download and set up one of the sample projects. After you're familiar with the APIs, leverage the samples in your own server-side code.
@@ -472,7 +472,7 @@ After downloading the zip, you can run the samples in the zip directly by settin
Running any sample or custom code requires the following steps:
-1. Install [Node.js 14.0](https://nodejs.org/en/download/) or higher.
+1. Install [Node.js 18.0](https://nodejs.org/en/download/) or higher.
diff --git a/src/pages/overview/pdf-extract-api/howtos/extract-api.md b/src/pages/overview/pdf-extract-api/howtos/extract-api.md
index 9f103086a..05610e503 100644
--- a/src/pages/overview/pdf-extract-api/howtos/extract-api.md
+++ b/src/pages/overview/pdf-extract-api/howtos/extract-api.md
@@ -293,48 +293,74 @@ namespace ExtractTextInfoFromPDF
// Run the sample:
// node src/extractpdf/extract-text-info-from-pdf.js
- const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');
- try {
- // Initial setup, create credentials instance.
- const credentials = PDFServicesSdk.Credentials
- .servicePrincipalCredentialsBuilder()
- .withClientId("PDF_SERVICES_CLIENT_ID")
- .withClientSecret("PDF_SERVICES_CLIENT_SECRET")
- .build();
-
- // Create an ExecutionContext using credentials
- const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);
-
- // Build extractPDF options
- const options = new PDFServicesSdk.ExtractPDF.options.ExtractPdfOptions.Builder()
- .addElementsToExtract(PDFServicesSdk.ExtractPDF.options.ExtractElementType.TEXT).build();
-
- // Create a new operation instance.
- const extractPDFOperation = PDFServicesSdk.ExtractPDF.Operation.createNew(),
- input = PDFServicesSdk.FileRef.createFromLocalFile(
- 'resources/extractPDFInput.pdf',
- PDFServicesSdk.ExtractPDF.SupportedSourceFormat.pdf
- );
-
- // Set operation input from a source file.
- extractPDFOperation.setInput(input);
-
- // Set options
- extractPDFOperation.setOptions(options);
-
- extractPDFOperation.execute(executionContext)
- .then(result => result.saveAsFile('output/ExtractTextInfoFromPDF.zip'))
- .catch(err => {
- if(err instanceof PDFServicesSdk.Error.ServiceApiError
- || err instanceof PDFServicesSdk.Error.ServiceUsageError) {
- console.log('Exception encountered while executing operation', err);
- } else {
- console.log('Exception encountered while executing operation', err);
- }
- });
- } catch (err) {
- console.log('Exception encountered while executing operation', err);
- }
+const {
+ ServicePrincipalCredentials,
+ PDFServices,
+ MimeType,
+ ExtractPDFParams,
+ ExtractElementType,
+ ExtractPDFJob,
+ ExtractPDFResult,
+ SDKError,
+ ServiceUsageError,
+ ServiceApiError
+} = require("@adobe/pdfservices-node-sdk");
+const fs = require("fs");
+
+(async () => {
+ let readStream;
+ try {
+ // Initial setup, create credentials instance
+ const credentials = new ServicePrincipalCredentials({
+ clientId: process.env.PDF_SERVICES_CLIENT_ID,
+ clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET
+ });
+
+ // Creates a PDF Services instance
+ const pdfServices = new PDFServices({credentials});
+
+ // Creates an asset(s) from source file(s) and upload
+ readStream = fs.createReadStream("./extractPDFInput.pdf");
+ const inputAsset = await pdfServices.upload({
+ readStream,
+ mimeType: MimeType.PDF
+ });
+
+ // Create parameters for the job
+ const params = new ExtractPDFParams({
+ elementsToExtract: [ExtractElementType.TEXT]
+ });
+
+ // Creates a new job instance
+ const job = new ExtractPDFJob({inputAsset, params});
+
+ // Submit the job and get the job result
+ const pollingURL = await pdfServices.submit({job});
+ const pdfServicesResponse = await pdfServices.getJobResult({
+ pollingURL,
+ resultType: ExtractPDFResult
+ });
+
+ // Get content from the resulting asset(s)
+ const resultAsset = pdfServicesResponse.result.resource;
+ const streamAsset = await pdfServices.getContent({asset: resultAsset});
+
+ // Creates a write stream and copy stream asset's content to it
+ const outputFilePath = "./ExtractTextInfoFromPDF.zip";
+ console.log(`Saving asset at ${outputFilePath}`);
+
+ const writeStream = fs.createWriteStream(outputFilePath);
+ streamAsset.readStream.pipe(writeStream);
+ } catch (err) {
+ if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {
+ console.log("Exception encountered while executing operation", err);
+ } else {
+ console.log("Exception encountered while executing operation", err);
+ }
+ } finally {
+ readStream?.destroy();
+ }
+})();
```
#### Python
@@ -547,51 +573,74 @@ namespace ExtractTextTableInfoFromPDF
// Run the sample:
// node src/extractpdf/extract-text-table-info-from-pdf.js
+const {
+ ServicePrincipalCredentials,
+ PDFServices,
+ MimeType,
+ ExtractPDFParams,
+ ExtractElementType,
+ ExtractPDFJob,
+ ExtractPDFResult,
+ SDKError,
+ ServiceUsageError,
+ ServiceApiError
+} = require("@adobe/pdfservices-node-sdk");
+const fs = require("fs");
+
+(async () => {
+ let readStream;
+ try {
+ // Initial setup, create credentials instance
+ const credentials = new ServicePrincipalCredentials({
+ clientId: process.env.PDF_SERVICES_CLIENT_ID,
+ clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET
+ });
- const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');
- try {
- // Initial setup, create credentials instance.
- const credentials = PDFServicesSdk.Credentials
- .servicePrincipalCredentialsBuilder()
- .withClientId("PDF_SERVICES_CLIENT_ID")
- .withClientSecret("PDF_SERVICES_CLIENT_SECRET")
- .build();
-
- // Create an ExecutionContext using credentials
- const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);
-
- // Build extractPDF options
- const options = new PDFServicesSdk.ExtractPDF.options.ExtractPdfOptions.Builder()
- .addElementsToExtract(PDFServicesSdk.ExtractPDF.options.ExtractElementType.TEXT, PDFServicesSdk.ExtractPDF.options.ExtractElementType.TABLES)
- .build();
-
- // Create a new operation instance.
- const extractPDFOperation = PDFServicesSdk.ExtractPDF.Operation.createNew(),
- input = PDFServicesSdk.FileRef.createFromLocalFile(
- 'resources/extractPDFInput.pdf',
- PDFServicesSdk.ExtractPDF.SupportedSourceFormat.pdf
- );
-
- // Set operation input from a source file.
- extractPDFOperation.setInput(input);
-
- // Set options
- extractPDFOperation.setOptions(options);
-
- extractPDFOperation.execute(executionContext)
- .then(result => result.saveAsFile('output/ExtractTextTableInfoFromPDF.zip'))
- .catch(err => {
- if(err instanceof PDFServicesSdk.Error.ServiceApiError
- || err instanceof PDFServicesSdk.Error.ServiceUsageError) {
- console.log('Exception encountered while executing operation', err);
- } else {
- console.log('Exception encountered while executing operation', err);
- }
- });
- } catch (err) {
- console.log('Exception encountered while executing operation', err);
- }
+ // Creates a PDF Services instance
+ const pdfServices = new PDFServices({credentials});
+
+ // Creates an asset(s) from source file(s) and upload
+ readStream = fs.createReadStream("./extractPDFInput.pdf");
+ const inputAsset = await pdfServices.upload({
+ readStream,
+ mimeType: MimeType.PDF
+ });
+
+ // Create parameters for the job
+ const params = new ExtractPDFParams({
+ elementsToExtract: [ExtractElementType.TEXT, ExtractElementType.TABLES]
+ });
+
+ // Creates a new job instance
+ const job = new ExtractPDFJob({inputAsset, params});
+
+ // Submit the job and get the job result
+ const pollingURL = await pdfServices.submit({job});
+ const pdfServicesResponse = await pdfServices.getJobResult({
+ pollingURL,
+ resultType: ExtractPDFResult
+ });
+
+ // Get content from the resulting asset(s)
+ const resultAsset = pdfServicesResponse.result.resource;
+ const streamAsset = await pdfServices.getContent({asset: resultAsset});
+
+ // Creates a write stream and copy stream asset's content to it
+ const outputFilePath = "./ExtractTextTableInfoFromPDF.zip";
+ console.log(`Saving asset at ${outputFilePath}`);
+ const writeStream = fs.createWriteStream(outputFilePath);
+ streamAsset.readStream.pipe(writeStream);
+ } catch (err) {
+ if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {
+ console.log("Exception encountered while executing operation", err);
+ } else {
+ console.log("Exception encountered while executing operation", err);
+ }
+ } finally {
+ readStream?.destroy();
+ }
+})();
```
#### Python
@@ -808,51 +857,76 @@ namespace ExtractTextTableInfoWithRenditionsFromPDF
// Run the sample:
// node src/extractpdf/extract-text-table-info-with-tables-renditions-from-pdf.js
- const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');
- try {
- // Initial setup, create credentials instance.
- const credentials = PDFServicesSdk.Credentials
- .servicePrincipalCredentialsBuilder()
- .withClientId("PDF_SERVICES_CLIENT_ID")
- .withClientSecret("PDF_SERVICES_CLIENT_SECRET")
- .build();
-
- // Create an ExecutionContext using credentials
- const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);
-
- // Build extractPDF options
- const options = new PDFServicesSdk.ExtractPDF.options.ExtractPdfOptions.Builder()
- .addElementsToExtract(PDFServicesSdk.ExtractPDF.options.ExtractElementType.TEXT, PDFServicesSdk.ExtractPDF.options.ExtractElementType.TABLES)
- .addElementsToExtractRenditions(PDFServicesSdk.ExtractPDF.options.ExtractRenditionsElementType.TABLES)
- .build();
-
- // Create a new operation instance.
- const extractPDFOperation = PDFServicesSdk.ExtractPDF.Operation.createNew(),
- input = PDFServicesSdk.FileRef.createFromLocalFile(
- 'resources/extractPDFInput.pdf',
- PDFServicesSdk.ExtractPDF.SupportedSourceFormat.pdf
- );
-
- // Set operation input from a source file
- extractPDFOperation.setInput(input);
-
- // Set options
- extractPDFOperation.setOptions(options);
-
- extractPDFOperation.execute(executionContext)
- .then(result => result.saveAsFile('output/ExtractTextTableInfoWithTablesRenditionsFromPDF.zip'))
- .catch(err => {
- if(err instanceof PDFServicesSdk.Error.ServiceApiError
- || err instanceof PDFServicesSdk.Error.ServiceUsageError) {
- console.log('Exception encountered while executing operation', err);
- } else {
- console.log('Exception encountered while executing operation', err);
- }
- });
- } catch (err) {
- console.log('Exception encountered while executing operation', err);
- }
-
+const {
+ ServicePrincipalCredentials,
+ PDFServices,
+ MimeType,
+ ExtractPDFParams,
+ ExtractElementType,
+ ExtractPDFJob,
+ ExtractPDFResult,
+ ExtractRenditionsElementType,
+ SDKError,
+ ServiceUsageError,
+ ServiceApiError
+} = require("@adobe/pdfservices-node-sdk");
+const fs = require("fs");
+
+(async () => {
+ let readStream;
+ try {
+ // Initial setup, create credentials instance
+ const credentials = new ServicePrincipalCredentials({
+ clientId: process.env.PDF_SERVICES_CLIENT_ID,
+ clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET
+ });
+
+ // Creates a PDF Services instance
+ const pdfServices = new PDFServices({credentials});
+
+ // Creates an asset(s) from source file(s) and upload
+ readStream = fs.createReadStream("./extractPDFInput.pdf");
+ const inputAsset = await pdfServices.upload({
+ readStream,
+ mimeType: MimeType.PDF
+ });
+
+ // Create parameters for the job
+ const params = new ExtractPDFParams({
+ elementsToExtract: [ExtractElementType.TEXT, ExtractElementType.TABLES],
+ elementsToExtractRenditions: [ExtractRenditionsElementType.TABLES]
+ });
+
+ // Creates a new job instance
+ const job = new ExtractPDFJob({inputAsset, params});
+
+ // Submit the job and get the job result
+ const pollingURL = await pdfServices.submit({job});
+ const pdfServicesResponse = await pdfServices.getJobResult({
+ pollingURL,
+ resultType: ExtractPDFResult
+ });
+
+ // Get content from the resulting asset(s)
+ const resultAsset = pdfServicesResponse.result.resource;
+ const streamAsset = await pdfServices.getContent({asset: resultAsset});
+
+ // Creates a write stream and copy stream asset's content to it
+ const outputFilePath = "./ExtractTextTableInfoWithRenditionsFromPDF.zip";
+ console.log(`Saving asset at ${outputFilePath}`);
+
+ const writeStream = fs.createWriteStream(outputFilePath);
+ streamAsset.readStream.pipe(writeStream);
+ } catch (err) {
+ if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {
+ console.log("Exception encountered while executing operation", err);
+ } else {
+ console.log("Exception encountered while executing operation", err);
+ }
+ } finally {
+ readStream?.destroy();
+ }
+})();
```
#### Python
@@ -1072,50 +1146,76 @@ namespace ExtractTextTableInfoWithFiguresTablesRenditionsFromPDF
// Run the sample:
// node src/extractpdf/extract-text-table-info-with-figures-tables-renditions-from-pdf.js
-const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');
-try {
- // Initial setup, create credentials instance.
- const credentials = PDFServicesSdk.Credentials
- .servicePrincipalCredentialsBuilder()
- .withClientId("PDF_SERVICES_CLIENT_ID")
- .withClientSecret("PDF_SERVICES_CLIENT_SECRET")
- .build();
-
- // Create an ExecutionContext using credentials
- const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);
-
- // Build extractPDF options
- const options = new PDFServicesSdk.ExtractPDF.options.ExtractPdfOptions.Builder()
- .addElementsToExtract(PDFServicesSdk.ExtractPDF.options.ExtractElementType.TEXT, PDFServicesSdk.ExtractPDF.options.ExtractElementType.TABLES)
- .addElementsToExtractRenditions(PDFServicesSdk.ExtractPDF.options.ExtractRenditionsElementType.FIGURES, PDFServicesSdk.ExtractPDF.options.ExtractRenditionsElementType.TABLES)
- .build();
-
- // Create a new operation instance.
- const extractPDFOperation = PDFServicesSdk.ExtractPDF.Operation.createNew(),
- input = PDFServicesSdk.FileRef.createFromLocalFile(
- 'resources/extractPDFInput.pdf',
- PDFServicesSdk.ExtractPDF.SupportedSourceFormat.pdf
- );
-
- // Set operation input from a source file
- extractPDFOperation.setInput(input);
-
- // Set options
- extractPDFOperation.setOptions(options);
-
- extractPDFOperation.execute(executionContext)
- .then(result => result.saveAsFile('output/ExtractTextTableWithFigureTableRendition.zip'))
- .catch(err => {
- if(err instanceof PDFServicesSdk.Error.ServiceApiError
- || err instanceof PDFServicesSdk.Error.ServiceUsageError) {
- console.log('Exception encountered while executing operation', err);
- } else {
- console.log('Exception encountered while executing operation', err);
- }
+const {
+ ServicePrincipalCredentials,
+ PDFServices,
+ MimeType,
+ ExtractPDFParams,
+ ExtractElementType,
+ ExtractPDFJob,
+ ExtractPDFResult,
+ ExtractRenditionsElementType,
+ SDKError,
+ ServiceUsageError,
+ ServiceApiError
+} = require("@adobe/pdfservices-node-sdk");
+const fs = require("fs");
+
+(async () => {
+ let readStream;
+ try {
+ // Initial setup, create credentials instance
+ const credentials = new ServicePrincipalCredentials({
+ clientId: process.env.PDF_SERVICES_CLIENT_ID,
+ clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET
});
-} catch (err) {
- console.log('Exception encountered while executing operation', err);
-}
+
+ // Creates a PDF Services instance
+ const pdfServices = new PDFServices({credentials});
+
+ // Creates an asset(s) from source file(s) and upload
+ readStream = fs.createReadStream("./extractPDFInput.pdf");
+ const inputAsset = await pdfServices.upload({
+ readStream,
+ mimeType: MimeType.PDF
+ });
+
+ // Create parameters for the job
+ const params = new ExtractPDFParams({
+ elementsToExtract: [ExtractElementType.TEXT, ExtractElementType.TABLES],
+ elementsToExtractRenditions: [ExtractRenditionsElementType.FIGURES, ExtractRenditionsElementType.TABLES]
+ });
+
+ // Creates a new job instance
+ const job = new ExtractPDFJob({inputAsset, params});
+
+ // Submit the job and get the job result
+ const pollingURL = await pdfServices.submit({job});
+ const pdfServicesResponse = await pdfServices.getJobResult({
+ pollingURL,
+ resultType: ExtractPDFResult
+ });
+
+ // Get content from the resulting asset(s)
+ const resultAsset = pdfServicesResponse.result.resource;
+ const streamAsset = await pdfServices.getContent({asset: resultAsset});
+
+ // Creates a write stream and copy stream asset's content to it
+ const outputFilePath = "./ExtractTextTableWithFigureTableRendition.zip";
+ console.log(`Saving asset at ${outputFilePath}`);
+
+ const writeStream = fs.createWriteStream(outputFilePath);
+ streamAsset.readStream.pipe(writeStream);
+ } catch (err) {
+ if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {
+ console.log("Exception encountered while executing operation", err);
+ } else {
+ console.log("Exception encountered while executing operation", err);
+ }
+ } finally {
+ readStream?.destroy();
+ }
+})();
```
#### Python
@@ -1336,50 +1436,75 @@ namespace ExtractTextTableInfoWithCharBoundsFromPDF
// Run the sample:
// node src/extractpdf/extract-text-table-info-with-char-bounds-from-pdf.js
- const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');
- try {
- // Initial setup, create credentials instance.
- const credentials = PDFServicesSdk.Credentials
- .servicePrincipalCredentialsBuilder()
- .withClientId("PDF_SERVICES_CLIENT_ID")
- .withClientSecret("PDF_SERVICES_CLIENT_SECRET")
- .build();
-
- // Create an ExecutionContext using credentials
- const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);
-
- // Build extractPDF options
- const options = new PDFServicesSdk.ExtractPDF.options.ExtractPdfOptions.Builder()
- .addElementsToExtract(PDFServicesSdk.ExtractPDF.options.ExtractElementType.TEXT, PDFServicesSdk.ExtractPDF.options.ExtractElementType.TABLES)
- .addCharInfo(true)
- .build();
-
- // Create a new operation instance.
- const extractPDFOperation = PDFServicesSdk.ExtractPDF.Operation.createNew(),
- input = PDFServicesSdk.FileRef.createFromLocalFile(
- 'resources/extractPDFInput.pdf',
- PDFServicesSdk.ExtractPDF.SupportedSourceFormat.pdf
- );
-
- // Set operation input from a source file.
- extractPDFOperation.setInput(input);
-
- // Set options
- extractPDFOperation.setOptions(options);
-
- extractPDFOperation.execute(executionContext)
- .then(result => result.saveAsFile('output/ExtractTextTableInfoWithCharBoundsFromPDF.zip'))
- .catch(err => {
- if(err instanceof PDFServicesSdk.Error.ServiceApiError
- || err instanceof PDFServicesSdk.Error.ServiceUsageError) {
- console.log('Exception encountered while executing operation', err);
- } else {
- console.log('Exception encountered while executing operation', err);
- }
- });
- } catch (err) {
- console.log('Exception encountered while executing operation', err);
- }
+const {
+ ServicePrincipalCredentials,
+ PDFServices,
+ MimeType,
+ ExtractPDFParams,
+ ExtractElementType,
+ ExtractPDFJob,
+ ExtractPDFResult,
+ SDKError,
+ ServiceUsageError,
+ ServiceApiError
+} = require("@adobe/pdfservices-node-sdk");
+const fs = require("fs");
+
+(async () => {
+ let readStream;
+ try {
+ // Initial setup, create credentials instance
+ const credentials = new ServicePrincipalCredentials({
+ clientId: process.env.PDF_SERVICES_CLIENT_ID,
+ clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET
+ });
+
+ // Creates a PDF Services instance
+ const pdfServices = new PDFServices({credentials});
+
+ // Creates an asset(s) from source file(s) and upload
+ readStream = fs.createReadStream("./extractPDFInput.pdf");
+ const inputAsset = await pdfServices.upload({
+ readStream,
+ mimeType: MimeType.PDF
+ });
+
+ // Create parameters for the job
+ const params = new ExtractPDFParams({
+ elementsToExtract: [ExtractElementType.TEXT, ExtractElementType.TABLES],
+ addCharInfo: true
+ });
+
+ // Creates a new job instance
+ const job = new ExtractPDFJob({inputAsset, params});
+
+ // Submit the job and get the job result
+ const pollingURL = await pdfServices.submit({job});
+ const pdfServicesResponse = await pdfServices.getJobResult({
+ pollingURL,
+ resultType: ExtractPDFResult
+ });
+
+ // Get content from the resulting asset(s)
+ const resultAsset = pdfServicesResponse.result.resource;
+ const streamAsset = await pdfServices.getContent({asset: resultAsset});
+
+ // Creates a write stream and copy stream asset's content to it
+ const outputFilePath = "./ExtractTextTableInfoWithCharBoundsFromPDF.zip";
+ console.log(`Saving asset at ${outputFilePath}`);
+
+ const writeStream = fs.createWriteStream(outputFilePath);
+ streamAsset.readStream.pipe(writeStream);
+ } catch (err) {
+ if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {
+ console.log("Exception encountered while executing operation", err);
+ } else {
+ console.log("Exception encountered while executing operation", err);
+ }
+ } finally {
+ readStream?.destroy();
+ }
+})();
```
#### Python
@@ -1601,53 +1726,80 @@ namespace ExtractTextTableInfoWithTableStructureFromPDF
```javascript
// Get the samples from http://www.adobe.com/go/pdftoolsapi_node_sample
// Run the sample:
-// node src/extractpdf/extract-text-table-info-with-tables-renditions-from-pdf.js
-
- const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');
+// node src/extractpdf/extract-text-table-info-with-tables-structure-from-pdf.js
+
+const {
+ ServicePrincipalCredentials,
+ PDFServices,
+ MimeType,
+ ExtractPDFParams,
+ ExtractElementType,
+ ExtractPDFJob,
+ ExtractPDFResult,
+ ExtractRenditionsElementType,
+ TableStructureType,
+ SDKError,
+ ServiceUsageError,
+ ServiceApiError
+} = require("@adobe/pdfservices-node-sdk");
+const fs = require("fs");
+
+(async () => {
+ let readStream;
try {
- // Initial setup, create credentials instance.
- const credentials = PDFServicesSdk.Credentials
- .servicePrincipalCredentialsBuilder()
- .withClientId("PDF_SERVICES_CLIENT_ID")
- .withClientSecret("PDF_SERVICES_CLIENT_SECRET")
- .build();
-
- // Create an ExecutionContext using credentials
- const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);
-
- // Build extractPDF options
- const options = new PDFServicesSdk.ExtractPDF.options.ExtractPdfOptions.Builder()
- .addElementsToExtract(PDFServicesSdk.ExtractPDF.options.ExtractElementType.TEXT, PDFServicesSdk.ExtractPDF.options.ExtractElementType.TABLES)
- .addElementsToExtractRenditions(PDFServicesSdk.ExtractPDF.options.ExtractRenditionsElementType.TABLES)
- .addTableStructureFormat(PDFServicesSdk.ExtractPDF.options.TableStructureType.CSV)
- .build();
-
- // Create a new operation instance.
- const extractPDFOperation = PDFServicesSdk.ExtractPDF.Operation.createNew(),
- input = PDFServicesSdk.FileRef.createFromLocalFile(
- 'resources/extractPDFInput.pdf',
- PDFServicesSdk.ExtractPDF.SupportedSourceFormat.pdf
- );
-
- // Set operation input from a source file.
- extractPDFOperation.setInput(input);
-
- // Set options
- extractPDFOperation.setOptions(options);
-
- extractPDFOperation.execute(executionContext)
- .then(result => result.saveAsFile('output/ExtractTextTableWithTableStructure.zip'))
- .catch(err => {
- if(err instanceof PDFServicesSdk.Error.ServiceApiError
- || err instanceof PDFServicesSdk.Error.ServiceUsageError) {
- console.log('Exception encountered while executing operation', err);
- } else {
- console.log('Exception encountered while executing operation', err);
- }
- });
+ // Initial setup, create credentials instance
+ const credentials = new ServicePrincipalCredentials({
+ clientId: process.env.PDF_SERVICES_CLIENT_ID,
+ clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET
+ });
+
+ // Creates a PDF Services instance
+ const pdfServices = new PDFServices({credentials});
+
+ // Creates an asset(s) from source file(s) and upload
+ readStream = fs.createReadStream("./extractPDFInput.pdf");
+ const inputAsset = await pdfServices.upload({
+ readStream,
+ mimeType: MimeType.PDF
+ });
+
+ // Create parameters for the job
+ const params = new ExtractPDFParams({
+ elementsToExtract: [ExtractElementType.TEXT, ExtractElementType.TABLES],
+ elementsToExtractRenditions: [ExtractRenditionsElementType.TABLES],
+ tableStructureType: TableStructureType.CSV
+ });
+
+ // Creates a new job instance
+ const job = new ExtractPDFJob({inputAsset, params});
+
+ // Submit the job and get the job result
+ const pollingURL = await pdfServices.submit({job});
+ const pdfServicesResponse = await pdfServices.getJobResult({
+ pollingURL,
+ resultType: ExtractPDFResult
+ });
+
+ // Get content from the resulting asset(s)
+ const resultAsset = pdfServicesResponse.result.resource;
+ const streamAsset = await pdfServices.getContent({asset: resultAsset});
+
+ // Creates a write stream and copy stream asset's content to it
+ const outputFilePath = "./ExtractTextTableWithTableStructure.zip";
+ console.log(`Saving asset at ${outputFilePath}`);
+
+ const writeStream = fs.createWriteStream(outputFilePath);
+ streamAsset.readStream.pipe(writeStream);
} catch (err) {
- console.log('Exception encountered while executing operation', err);
+ if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {
+ console.log("Exception encountered while executing operation", err);
+ } else {
+ console.log("Exception encountered while executing operation", err);
+ }
+ } finally {
+ readStream?.destroy();
}
+})();
```
#### Python
@@ -1870,51 +2022,75 @@ namespace ExtractTextTableInfoWithStylingFromPDF
// Run the sample:
// node src/extractpdf/extract-text-table-with-styling-info-from-pdf.js
-
- const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');
- try {
- // Initial setup, create credentials instance.
- const credentials = PDFServicesSdk.Credentials
- .servicePrincipalCredentialsBuilder()
- .withClientId("PDF_SERVICES_CLIENT_ID")
- .withClientSecret("PDF_SERVICES_CLIENT_SECRET")
- .build();
-
- // Create an ExecutionContext using credentials
- const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);
-
- // Build extractPDF options
- const options = new PDFServicesSdk.ExtractPDF.options.ExtractPdfOptions.Builder()
- .addElementsToExtract(PDFServicesSdk.ExtractPDF.options.ExtractElementType.TEXT, PDFServicesSdk.ExtractPDF.options.ExtractElementType.TABLES)
- .getStylingInfo(true)
- .build();
-
- // Create a new operation instance.
- const extractPDFOperation = PDFServicesSdk.ExtractPDF.Operation.createNew(),
- input = PDFServicesSdk.FileRef.createFromLocalFile(
- 'resources/extractPDFInput.pdf',
- PDFServicesSdk.ExtractPDF.SupportedSourceFormat.pdf
- );
-
- // Set operation input from a source file.
- extractPDFOperation.setInput(input);
-
- // Set options
- extractPDFOperation.setOptions(options);
-
- extractPDFOperation.execute(executionContext)
- .then(result => result.saveAsFile('output/ExtractTextTableInfoWithStylingInfoFromPDF.zip'))
- .catch(err => {
- if(err instanceof PDFServicesSdk.Error.ServiceApiError
- || err instanceof PDFServicesSdk.Error.ServiceUsageError) {
- console.log('Exception encountered while executing operation', err);
- } else {
- console.log('Exception encountered while executing operation', err);
- }
- });
- } catch (err) {
- console.log('Exception encountered while executing operation', err);
- }
+const {
+ ServicePrincipalCredentials,
+ PDFServices,
+ MimeType,
+ ExtractPDFParams,
+ ExtractElementType,
+ ExtractPDFJob,
+ ExtractPDFResult,
+ SDKError,
+ ServiceUsageError,
+ ServiceApiError
+} = require("@adobe/pdfservices-node-sdk");
+const fs = require("fs");
+
+(async () => {
+ let readStream;
+ try {
+ // Initial setup, create credentials instance
+ const credentials = new ServicePrincipalCredentials({
+ clientId: process.env.PDF_SERVICES_CLIENT_ID,
+ clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET
+ });
+
+ // Creates a PDF Services instance
+ const pdfServices = new PDFServices({credentials});
+
+ // Creates an asset(s) from source file(s) and upload
+ readStream = fs.createReadStream("./extractPDFInput.pdf");
+ const inputAsset = await pdfServices.upload({
+ readStream,
+ mimeType: MimeType.PDF
+ });
+
+ // Create parameters for the job
+ const params = new ExtractPDFParams({
+ elementsToExtract: [ExtractElementType.TEXT, ExtractElementType.TABLES],
+ getStylingInfo: true,
+ });
+
+ // Creates a new job instance
+ const job = new ExtractPDFJob({inputAsset, params});
+
+ // Submit the job and get the job result
+ const pollingURL = await pdfServices.submit({job});
+ const pdfServicesResponse = await pdfServices.getJobResult({
+ pollingURL,
+ resultType: ExtractPDFResult
+ });
+
+ // Get content from the resulting asset(s)
+ const resultAsset = pdfServicesResponse.result.resource;
+ const streamAsset = await pdfServices.getContent({asset: resultAsset});
+
+ // Creates a write stream and copy stream asset's content to it
+ const outputFilePath = "./ExtractTextTableInfoWithStylingInfoFromPDF.zip";
+ console.log(`Saving asset at ${outputFilePath}`);
+
+ const writeStream = fs.createWriteStream(outputFilePath);
+ streamAsset.readStream.pipe(writeStream);
+ } catch (err) {
+ if (err instanceof SDKError || err instanceof ServiceUsageError || err instanceof ServiceApiError) {
+ console.log("Exception encountered while executing operation", err);
+ } else {
+ console.log("Exception encountered while executing operation", err);
+ }
+ } finally {
+ readStream?.destroy();
+ }
+})();
```
#### Python
diff --git a/src/pages/overview/pdf-extract-api/howtos/index.md b/src/pages/overview/pdf-extract-api/howtos/index.md
index a13fa53b8..760226b0e 100644
--- a/src/pages/overview/pdf-extract-api/howtos/index.md
+++ b/src/pages/overview/pdf-extract-api/howtos/index.md
@@ -90,14 +90,8 @@ ClientConfig clientConfig = ClientConfig.ConfigBuilder()
Available properties:
-- **connectTimeout**: Default: 10000. The maximum allowed time in
- milliseconds for creating an initial HTTPS connection.
-- **readTimeout**: Default: 10000. The maximum allowed time in
- milliseconds between two successive HTTP response packets.
-- **processingTimeout**: Default: 600000. The maximum allowed time
- in milliseconds for processing the documents. Any operation taking more time than the specified `processingTimeout` will result in an operation timeout exception.
- - **Note :** It is advisable to set the `processingTimeout` to higher values for processing large files.
-
+- **timeout**: Default: 10000. The maximum allowed time in milliseconds before the request times out. If the request
+ takes longer than `timeout`, the request will be aborted.
Override the timeout properties via a custom `ClientConfig` class:
@@ -106,11 +100,9 @@ Override the timeout properties via a custom `ClientConfig` class:
###
```javascript
-const clientConfig = PDFServicesSdk.ClientConfig
- .clientConfigBuilder()
- .withConnectTimeout(15000)
- .withReadTimeout(15000)
- .build();
+const clientConfig = new ClientConfig({
+ timeout: 15000
+})
```
### Python timeout configuration
diff --git a/src/pages/overview/pdf-extract-api/quickstarts/nodejs/index.md b/src/pages/overview/pdf-extract-api/quickstarts/nodejs/index.md
index fd3fb0d88..3765d78e4 100644
--- a/src/pages/overview/pdf-extract-api/quickstarts/nodejs/index.md
+++ b/src/pages/overview/pdf-extract-api/quickstarts/nodejs/index.md
@@ -10,7 +10,7 @@ To get started using Adobe PDF Extract API, let's walk through a simple scenario
To complete this guide, you will need:
-* [Node.js](https://nodejs.org) - Node.js version 14.0 or higher is required.
+* [Node.js](https://nodejs.org) - Node.js version 18.0 or higher is required.
* An Adobe ID. If you do not have one, the credential setup will walk you through creating one.
* A way to edit code. No specific editor is required for this guide.
@@ -65,27 +65,20 @@ Now you're ready to begin coding.
1) We'll begin by including our required dependencies:
```js
-const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');
-const fs = require('fs');
+const {
+ ServicePrincipalCredentials,
+ PDFServices,
+ MimeType,
+ ExtractPDFParams,
+ ExtractElementType,
+ ExtractPDFJob,
+ ExtractPDFResult
+} = require("@adobe/pdfservices-node-sdk");
+const fs = require("fs");
const AdmZip = require('adm-zip');
```
-The first line includes the Adobe PDF Services Node.js SDK. The second third include Node's `filesystem` package as well as the package that will work with the ZIP file returned from the API.
-
-2) Now let's define our input and output:
-
-```js
-const OUTPUT_ZIP = './ExtractTextInfoFromPDF.zip';
-
-//Remove if the output already exists.
-if(fs.existsSync(OUTPUT_ZIP)) fs.unlinkSync(OUTPUT_ZIP);
-
-const INPUT_PDF = './Adobe Extract API Sample.pdf';
-```
-
-This defines what our output ZIP will be and optionally deletes it if it already exists. Then we define what PDF will be extracted. (You can download the source we used [here](/Adobe%20Extract%20API%20Sample.pdf).) In a real application, these values would be typically be dynamic.
-
-3) Set the environment variables `PDF_SERVICES_CLIENT_ID` and `PDF_SERVICES_CLIENT_SECRET` by running the following commands and replacing placeholders `YOUR CLIENT ID` and `YOUR CLIENT SECRET` with the credentials present in `pdfservices-api-credentials.json` file:
+2) Set the environment variables `PDF_SERVICES_CLIENT_ID` and `PDF_SERVICES_CLIENT_SECRET` by running the following commands and replacing placeholders `YOUR CLIENT ID` and `YOUR CLIENT SECRET` with the credentials present in `pdfservices-api-credentials.json` file:
- **Windows:**
- `set PDF_SERVICES_CLIENT_ID=`
- `set PDF_SERVICES_CLIENT_SECRET=`
@@ -94,70 +87,87 @@ This defines what our output ZIP will be and optionally deletes it if it already
- `export PDF_SERVICES_CLIENT_ID=`
- `export PDF_SERVICES_CLIENT_SECRET=`
-4) Next, we setup the SDK to use our credentials.
+3) Next, we setup the SDK to use our credentials.
```js
-const credentials = PDFServicesSdk.Credentials
- .servicePrincipalCredentialsBuilder()
- .withClientId(process.env.PDF_SERVICES_CLIENT_ID)
- .withClientSecret(process.env.PDF_SERVICES_CLIENT_SECRET)
- .build();
-
-// Create an ExecutionContext using credentials
-const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);
+// Initial setup, create credentials instance
+const credentials = new ServicePrincipalCredentials({
+ clientId: process.env.PDF_SERVICES_CLIENT_ID,
+ clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET
+});
+
+// Creates a PDF Services instance
+const pdfServices = new PDFServices({credentials});
```
-This code both points to the credentials downloaded previously as well as sets up an execution context object that will be used later.
+4) Now, let's upload the asset:
-5) Now, let's create the operation:
+```js
+const inputAsset = await pdfServices.upload({
+ readStream,
+ mimeType: MimeType.PDF
+});
+```
+We define what PDF will be extracted. (You can download the source we used [here](/Adobe%20Extract%20API%20Sample.pdf).) In a real application, these values would be typically be dynamic.
+5) Now, let's create the parameters and the job:
+
+```js
+// Create parameters for the job
+const params = new ExtractPDFParams({
+ elementsToExtract: [ExtractElementType.TEXT]
+});
+
+// Creates a new job instance
+const job = new ExtractPDFJob({inputAsset, params});
+```
+
+This set of code defines what we're doing (an Extract operation),
+it defines parameters for the Extract job. PDF Extract API has a few different options, but in this example, we're simply asking for the most basic of extractions, the textual content of the document.
+
+6) The next code block submits the job and gets the job result:
```js
-// Create a new operation instance.
-const extractPDFOperation = PDFServicesSdk.ExtractPDF.Operation.createNew(),
- input = PDFServicesSdk.FileRef.createFromLocalFile(
- INPUT_PDF,
- PDFServicesSdk.ExtractPDF.SupportedSourceFormat.pdf
- );
-
-// Build extractPDF options
-const options = new PDFServicesSdk.ExtractPDF.options.ExtractPdfOptions.Builder()
- .addElementsToExtract(PDFServicesSdk.ExtractPDF.options.ExtractElementType.TEXT).build()
-
-extractPDFOperation.setInput(input);
-extractPDFOperation.setOptions(options);
+// Submit the job and get the job result
+const pollingURL = await pdfServices.submit({job});
+const pdfServicesResponse = await pdfServices.getJobResult({
+ pollingURL,
+ resultType: ExtractPDFResult
+});
+
+// Get content from the resulting asset(s)
+const resultAsset = pdfServicesResponse.result.resource;
+const streamAsset = await pdfServices.getContent({asset: resultAsset});
```
-This set of code defines what we're doing (an Extract operation), points to our local file and specifies the input is a PDF, and then defines options for the Extract call. PDF Extract API has a few different options, but in this example, we're simply asking for the most basic of extractions, the textual content of the document.
+This code runs the Extraction process, gets the content of the result zip in stream asset.
-6) The next code block executes the operation:
+7) The next code block saves the result at the specified location:
```js
-// Execute the operation
-extractPDFOperation.execute(executionContext)
- .then(result => result.saveAsFile(OUTPUT_ZIP))
- .then(() => {
- console.log('Successfully extracted information from PDF.');
- })
- .catch(err => console.log(err));
+// Creates a write stream and copy stream asset's content to it
+const outputFilePath = "./ExtractTextInfoFromPDF.zip";
+console.log(`Saving asset at ${outputFilePath}`);
+
+const writeStream = fs.createWriteStream(outputFilePath);
+streamAsset.readStream.pipe(writeStream);
```
-This code runs the Extraction process and then stores the result zip to the file system.
+Here's the complete application (`extract.js`):
-7) In this block, we read in the ZIP file, extract the JSON result file, and parse it:
+8) In this block, we read in the ZIP file, extract the JSON result file, and parse it:
```js
-let zip = new AdmZip(OUTPUT_ZIP);
+let zip = new AdmZip(outputFilePath);
let jsondata = zip.readAsText('structuredData.json');
let data = JSON.parse(jsondata);
```
-
-8) Finally we can loop over the result and print out any found element that is an `H1`:
+9) Finally, we can loop over the result and print out any found element that is an `H1`:
```js
data.elements.forEach(element => {
- if(element.Path.endsWith('/H1')) {
- console.log(element.Text);
- }
+ if(element.Path.endsWith('/H1')) {
+ console.log(element.Text);
+ }
});
```
@@ -166,57 +176,77 @@ data.elements.forEach(element => {
Here's the complete application (`extract.js`):
```js
-const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');
-const fs = require('fs');
+const {
+ ServicePrincipalCredentials,
+ PDFServices,
+ MimeType,
+ ExtractPDFParams,
+ ExtractElementType,
+ ExtractPDFJob,
+ ExtractPDFResult
+} = require("@adobe/pdfservices-node-sdk");
+const fs = require("fs");
const AdmZip = require('adm-zip');
-const OUTPUT_ZIP = './ExtractTextInfoFromPDF.zip';
-
-//Remove if the output already exists.
-if(fs.existsSync(OUTPUT_ZIP)) fs.unlinkSync(OUTPUT_ZIP);
-
-const INPUT_PDF = './Adobe Extract API Sample.pdf';
-
-const credentials = PDFServicesSdk.Credentials
- .servicePrincipalCredentialsBuilder()
- .withClientId(process.env.PDF_SERVICES_CLIENT_ID)
- .withClientSecret(process.env.PDF_SERVICES_CLIENT_SECRET)
- .build();
-
-// Create an ExecutionContext using credentials
-const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);
-
-// Create a new operation instance.
-const extractPDFOperation = PDFServicesSdk.ExtractPDF.Operation.createNew(),
- input = PDFServicesSdk.FileRef.createFromLocalFile(
- INPUT_PDF,
- PDFServicesSdk.ExtractPDF.SupportedSourceFormat.pdf
- );
-
-// Build extractPDF options
-const options = new PDFServicesSdk.ExtractPDF.options.ExtractPdfOptions.Builder()
- .addElementsToExtract(PDFServicesSdk.ExtractPDF.options.ExtractElementType.TEXT).build()
-
-
-extractPDFOperation.setInput(input);
-extractPDFOperation.setOptions(options);
-
-// Execute the operation
-extractPDFOperation.execute(executionContext)
- .then(result => result.saveAsFile(OUTPUT_ZIP))
- .then(() => {
- console.log('Successfully extracted information from PDF. Printing H1 Headers:\n');
- let zip = new AdmZip(OUTPUT_ZIP);
- let jsondata = zip.readAsText('structuredData.json');
- let data = JSON.parse(jsondata);
- data.elements.forEach(element => {
- if(element.Path.endsWith('/H1')) {
- console.log(element.Text);
- }
- });
-
- })
- .catch(err => console.log(err));
+(async () => {
+ let readStream;
+ try {
+ // Initial setup, create credentials instance
+ const credentials = new ServicePrincipalCredentials({
+ clientId: process.env.PDF_SERVICES_CLIENT_ID,
+ clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET
+ });
+
+ // Creates a PDF Services instance
+ const pdfServices = new PDFServices({credentials});
+
+ // Creates an asset(s) from source file(s) and upload
+ readStream = fs.createReadStream("./Adobe Extract API Sample.pdf");
+ const inputAsset = await pdfServices.upload({
+ readStream,
+ mimeType: MimeType.PDF
+ });
+
+ // Create parameters for the job
+ const params = new ExtractPDFParams({
+ elementsToExtract: [ExtractElementType.TEXT]
+ });
+
+ // Creates a new job instance
+ const job = new ExtractPDFJob({inputAsset, params});
+
+ // Submit the job and get the job result
+ const pollingURL = await pdfServices.submit({job});
+ const pdfServicesResponse = await pdfServices.getJobResult({
+ pollingURL,
+ resultType: ExtractPDFResult
+ });
+
+ // Get content from the resulting asset(s)
+ const resultAsset = pdfServicesResponse.result.resource;
+ const streamAsset = await pdfServices.getContent({asset: resultAsset});
+
+ // Creates a write stream and copy stream asset's content to it
+ const outputFilePath = "./ExtractTextInfoFromPDF.zip";
+ console.log(`Saving asset at ${outputFilePath}`);
+
+ const writeStream = fs.createWriteStream(outputFilePath);
+ streamAsset.readStream.pipe(writeStream);
+
+ let zip = new AdmZip(outputFilePath);
+ let jsondata = zip.readAsText('structuredData.json');
+ let data = JSON.parse(jsondata);
+ data.elements.forEach(element => {
+ if(element.Path.endsWith('/H1')) {
+ console.log(element.Text);
+ }
+ });
+ } catch (err) {
+ console.log("Exception encountered while executing operation", err);
+ } finally {
+ readStream?.destroy();
+ }
+})();
```
## Next Steps
diff --git a/src/pages/overview/pdf-extract-api/quickstarts/nodejs/shot9.png b/src/pages/overview/pdf-extract-api/quickstarts/nodejs/shot9.png
index b09d4ce9f..0eb77ef8e 100644
Binary files a/src/pages/overview/pdf-extract-api/quickstarts/nodejs/shot9.png and b/src/pages/overview/pdf-extract-api/quickstarts/nodejs/shot9.png differ
diff --git a/src/pages/overview/pdf-services-api/gettingstarted.md b/src/pages/overview/pdf-services-api/gettingstarted.md
index 64ca1461b..9ade0651b 100644
--- a/src/pages/overview/pdf-services-api/gettingstarted.md
+++ b/src/pages/overview/pdf-services-api/gettingstarted.md
@@ -471,7 +471,7 @@ After downloading the zip, you can run the samples in the zip directly by settin
Running any sample or custom code requires the following steps:
-1. Install [Node.js 14.0](https://nodejs.org/en/download/) or higher.
+1. Install [Node.js 18.0](https://nodejs.org/en/download/) or higher.
diff --git a/src/pages/overview/pdf-services-api/quickstarts/nodejs/index.md b/src/pages/overview/pdf-services-api/quickstarts/nodejs/index.md
index 4ba1cc9d4..2f5165ea1 100644
--- a/src/pages/overview/pdf-services-api/quickstarts/nodejs/index.md
+++ b/src/pages/overview/pdf-services-api/quickstarts/nodejs/index.md
@@ -10,7 +10,7 @@ To get started using Adobe PDF Services API, let's walk through a simple scenari
To complete this guide, you will need:
-* [Node.js](https://nodejs.org) - Node.js version 14.0 or higher is required.
+* [Node.js](https://nodejs.org) - Node.js version 18.0 or higher is required.
* An Adobe ID. If you do not have one, the credential setup will walk you through creating one.
* A way to edit code. No specific editor is required for this guide.
@@ -63,24 +63,19 @@ Now you're ready to begin coding.
1) We'll begin by including our required dependencies:
```js
-const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');
-const fs = require('fs');
+const {
+ ServicePrincipalCredentials,
+ PDFServices,
+ MimeType,
+ ExportPDFParams,
+ ExportPDFTargetFormat,
+ ExportPDFJob,
+ ExportPDFResult
+} = require("@adobe/pdfservices-node-sdk");
+const fs = require("fs");
```
-The first line includes the Adobe PDF Services Node.js SDK. The second third include Node's `filesystem` package.
-
-2) Now let's define our input and output:
-
-```js
-const OUTPUT = './Bodea Brochure.docx';
-
-// If our output already exists, remove it so we can run the application again.
-if(fs.existsSync(OUTPUT)) fs.unlinkSync(OUTPUT);
-
-const INPUT = './Bodea Brochure.pdf';
-```
-
-3) Set the environment variables `PDF_SERVICES_CLIENT_ID` and `PDF_SERVICES_CLIENT_SECRET` by running the following commands and replacing placeholders `YOUR CLIENT ID` and `YOUR CLIENT SECRET` with the credentials present in `pdfservices-api-credentials.json` file:
+2) Set the environment variables `PDF_SERVICES_CLIENT_ID` and `PDF_SERVICES_CLIENT_SECRET` by running the following commands and replacing placeholders `YOUR CLIENT ID` and `YOUR CLIENT SECRET` with the credentials present in `pdfservices-api-credentials.json` file:
- **Windows:**
- `set PDF_SERVICES_CLIENT_ID=`
- `set PDF_SERVICES_CLIENT_SECRET=`
@@ -89,51 +84,64 @@ const INPUT = './Bodea Brochure.pdf';
- `export PDF_SERVICES_CLIENT_ID=`
- `export PDF_SERVICES_CLIENT_SECRET=`
-4) Next, we setup the SDK to use our credentials.
+3) Next, we can create our credentials and use them:
```js
-const credentials = PDFServicesSdk.Credentials
- .servicePrincipalCredentialsBuilder()
- .withClientId(process.env.PDF_SERVICES_CLIENT_ID)
- .withClientSecret(process.env.PDF_SERVICES_CLIENT_SECRET)
- .build();
-
-// Create an ExecutionContext using credentials
-const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);
+// Initial setup, create credentials instance
+const credentials = new ServicePrincipalCredentials({
+ clientId: process.env.PDF_SERVICES_CLIENT_ID,
+ clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET
+});
+
+// Creates a PDF Services instance
+const pdfServices = new PDFServices({credentials});
```
-This code both points to the credentials downloaded previously as well as sets up an execution context object that will be used later.
+4) Now, let's upload the asset:
-5) Now, let's create the operation:
+```js
+const inputAsset = await pdfServices.upload({
+ readStream,
+ mimeType: MimeType.PDF
+});
+```
+
+5) Now, let's create the parameters and the job:
```js
-// This creates an instance of the Export operation we're using, as well as specifying output type (DOCX)
-const exportPdfOperation = PDFServicesSdk.ExportPDF.Operation.createNew(PDFServicesSdk.ExportPDF.SupportedTargetFormats.DOCX);
+// Create parameters for the job
+const params = new ExportPDFParams({
+ targetFormat: ExportPDFTargetFormat.DOCX
+});
-// Set operation input from a source file
-const inputPDF = PDFServicesSdk.FileRef.createFromLocalFile(INPUT);
-exportPdfOperation.setInput(inputPDF);
+// Creates a new job instance
+const job = new ExportPDFJob({inputAsset, params});
```
-This set of code defines what we're doing (an Export operation), points to our local file and specifies the input is a PDF, and then defines options for the Export call. In this example, the only option is the export format, DOCX.
+This set of code defines what we're doing (an Export operation), and sets parameter for the Export PDF job.
+In this example, the only parameter is the export format ,ie, DOCX.
+
+6) The next code block submits the job and gets the job result:
+
+```js
+// Submit the job and get the job result
+const pollingURL = await pdfServices.submit({job});
+const pdfServicesResponse = await pdfServices.getJobResult({
+ pollingURL,
+ resultType: ExportPDFResult
+});
+
+// Get content from the resulting asset(s)
+const resultAsset = pdfServicesResponse.result.asset;
+const streamAsset = await pdfServices.getContent({asset: resultAsset});
+```
-6) The next code block executes the operation:
+7) The next code block saves the result at the specified location:
```js
-try {
-
- exportPdfOperation.execute(executionContext)
- .then(result => result.saveAsFile(OUTPUT))
- .then(() => {
- console.log('Export Done')
- })
- .catch(err => {
- console.log('Exception encountered while executing operation', err);
- });
-
-} catch(err) {
- console.error('Error:', err);
-}
+// Creates an output stream and copy stream asset's content to it
+const outputStream = fs.createWriteStream("./Bodea Brochure.docx");
+streamAsset.readStream.pipe(outputStream);
```
This code runs the Export process and then stores the result Word document to the file system.
@@ -143,50 +151,66 @@ This code runs the Export process and then stores the result Word document to th
Here's the complete application (`export.js`):
```js
-const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');
-const fs = require('fs');
-
-const OUTPUT = './Bodea Brochure.docx';
-
-// If our output already exists, remove it so we can run the application again.
-if(fs.existsSync(OUTPUT)) fs.unlinkSync(OUTPUT);
-
-const INPUT = './Bodea Brochure.pdf';
-
-
-console.log(`About to export ${INPUT} to ${OUTPUT}.`);
-
-// Set up our credentials object.
-const credentials = PDFServicesSdk.Credentials
- .servicePrincipalCredentialsBuilder()
- .withClientId(process.env.PDF_SERVICES_CLIENT_ID)
- .withClientSecret(process.env.PDF_SERVICES_CLIENT_SECRET)
- .build();
-
-// An exectuionContext object wraps our credentials
-const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);
-
-// This creates an instance of the Export operation we're using, as well as specifying output type (DOCX)
-const exportPdfOperation = PDFServicesSdk.ExportPDF.Operation.createNew(PDFServicesSdk.ExportPDF.SupportedTargetFormats.DOCX);
-
-// Set operation input from a source file
-const inputPDF = PDFServicesSdk.FileRef.createFromLocalFile(INPUT);
-exportPdfOperation.setInput(inputPDF);
-
-try {
-
- exportPdfOperation.execute(executionContext)
- .then(result => result.saveAsFile(OUTPUT))
- .then(() => {
- console.log('Export Done')
- })
- .catch(err => {
- console.log('Exception encountered while executing operation', err);
- });
-
-} catch(err) {
- console.error('Error:', err);
-}
+const {
+ ServicePrincipalCredentials,
+ PDFServices,
+ MimeType,
+ ExportPDFParams,
+ ExportPDFTargetFormat,
+ ExportPDFJob,
+ ExportPDFResult
+} = require("@adobe/pdfservices-node-sdk");
+const fs = require("fs");
+
+(async () => {
+ let readStream;
+ try {
+ // Initial setup, create credentials instance
+ const credentials = new ServicePrincipalCredentials({
+ clientId: process.env.PDF_SERVICES_CLIENT_ID,
+ clientSecret: process.env.PDF_SERVICES_CLIENT_SECRET
+ });
+
+ // Creates a PDF Services instance
+ const pdfServices = new PDFServices({credentials});
+
+ // Creates an asset(s) from source file(s) and upload
+ readStream = fs.createReadStream("./Bodea Brochure.pdf");
+ const inputAsset = await pdfServices.upload({
+ readStream,
+ mimeType: MimeType.PDF
+ });
+
+ // Create parameters for the job
+ const params = new ExportPDFParams({
+ targetFormat: ExportPDFTargetFormat.DOCX
+ });
+
+ // Creates a new job instance
+ const job = new ExportPDFJob({inputAsset, params});
+
+ // Submit the job and get the job result
+ const pollingURL = await pdfServices.submit({job});
+ const pdfServicesResponse = await pdfServices.getJobResult({
+ pollingURL,
+ resultType: ExportPDFResult
+ });
+
+ // Get content from the resulting asset(s)
+ const resultAsset = pdfServicesResponse.result.asset;
+ const streamAsset = await pdfServices.getContent({asset: resultAsset});
+
+ // Creates an output stream and copy stream asset's content to it
+ const outputFilePath = "./Bodea Brochure.docx";
+ console.log(`Saving asset at ${outputFilePath}`);
+ const outputStream = fs.createWriteStream(outputFilePath);
+ streamAsset.readStream.pipe(outputStream);
+ } catch (err) {
+ console.log("Exception encountered while executing operation", err);
+ } finally {
+ readStream?.destroy();
+ }
+})();
```
## Next Steps
diff --git a/src/pages/overview/pdf-services-api/quickstarts/nodejs/shot9.png b/src/pages/overview/pdf-services-api/quickstarts/nodejs/shot9.png
index b48baa077..f629ac0ac 100644
Binary files a/src/pages/overview/pdf-services-api/quickstarts/nodejs/shot9.png and b/src/pages/overview/pdf-services-api/quickstarts/nodejs/shot9.png differ
diff --git a/src/pages/overview/pdf-services-api/releasenotes.md b/src/pages/overview/pdf-services-api/releasenotes.md
index 580744f44..8cf6d1975 100644
--- a/src/pages/overview/pdf-services-api/releasenotes.md
+++ b/src/pages/overview/pdf-services-api/releasenotes.md
@@ -73,7 +73,7 @@ import com.adobe.pdfservices.operation.ExecutionContext;
* Update the latest SDK dependency in package.json file of your project
```
-"@adobe/pdfservices-node-sdk": "3.4.2"
+"@adobe/pdfservices-node-sdk": "4.0.0"
```
* Require the `@adobe/pdfservices-node-sdk` in the Sample file to access the SDK interface
@@ -129,6 +129,15 @@ Upgrading to the latest SDK should not break existing applications.
## Change history
+### 4.0.0 (April, 2024; major release)
+| Change | Language | Description |
+|---------|----------|--------------------------------------------------------------------------------------------------------------------------------|
+| New | NodeJS | Released Adobe PDF Services Node SDK v4.0.0, introducing new interfaces fully leveraging power of new PDF Services rest APIs. |
+| New | NodeJS | Added support for delete asset, refresh download URI, webhook notifiers. |
+| New | NodeJS | Eliminated need of storage to save intermediate result by removed dependency on temporary storage. |
+| New | NodeJS | Extended I/O capabilities by introducing external storage for a majority of PDF Services operations. |
+| Changed | NodeJS | Updated Extract PDF operation to return content and resource asset along with content JSON object. |
+
### 2.3.1 (March, 2024; patch release)
| Change | Language | Description |
diff --git a/src/pages/overview/releasenotes.md b/src/pages/overview/releasenotes.md
index fe854710b..f146cdc89 100644
--- a/src/pages/overview/releasenotes.md
+++ b/src/pages/overview/releasenotes.md
@@ -116,7 +116,7 @@ import com.adobe.pdfservices.operation.ExecutionContext;
* Update the latest SDK dependency in package.json file of your project
```
-"@adobe/pdfservices-node-sdk": "3.4.2"
+"@adobe/pdfservices-node-sdk": "4.0.0"
```
* Require the `@adobe/pdfservices-node-sdk` in the Sample file to access the SDK interface
@@ -173,6 +173,16 @@ Upgrading to the latest SDK should not break existing applications.
## Change history
+### 4.0.0 (April, 2024; major release)
+| Change | Language | Description |
+|---------|----------|--------------------------------------------------------------------------------------------------------------------------------|
+| New | NodeJS | Released Adobe PDF Services Node SDK v4.0.0, introducing new interfaces fully leveraging power of new PDF Services rest APIs. |
+| New | NodeJS | Added support for delete asset, refresh download URI, webhook notifiers. |
+| New | NodeJS | Eliminated need of storage to save intermediate result by removed dependency on temporary storage. |
+| New | NodeJS | Extended I/O capabilities by introducing external storage for a majority of PDF Services operations. |
+| Changed | NodeJS | Updated Extract PDF operation to return content and resource asset along with content JSON object. |
+
+
### 2.3.1 (March, 2024; patch release)
| Change | Language | Description |