diff --git a/nodejs/01-detect-text-local.js b/nodejs/01-detect-text-local.js new file mode 100644 index 0000000..94f0f12 --- /dev/null +++ b/nodejs/01-detect-text-local.js @@ -0,0 +1,21 @@ +/*Example showing processing a document on local machine.*/ + +const aws = require('aws-sdk'); +/*Initializing Textract from AWS SDK JS*/ +const textract = new aws.Textract({ apiVersion: "2018-06-27" }); +/*File system package for importing images and converting the image data to ByteArray */ +const fs = require('fs'); + +exports.handler = async(event, context) => { + let textractParams = { + Document: { + Bytes: fs.readFileSync("simple-document-image.jpg") + }, + }; + try { + let response = await textract.detectDocumentText(params).promise(); + console.log(JSON.stringify(response),null,2) + }catch(e){ + console.log("Error: ",e) + } +} \ No newline at end of file diff --git a/nodejs/02-detect-text-s3.js b/nodejs/02-detect-text-s3.js new file mode 100644 index 0000000..9772b24 --- /dev/null +++ b/nodejs/02-detect-text-s3.js @@ -0,0 +1,24 @@ +/*Example showing processing a document on AWS S3 bucket.*/ + +const aws = require('aws-sdk'); +/*Initializing Textract from AWS SDK JS*/ +const textract = new aws.Textract({ apiVersion: "2018-06-27" }); +const s3BucketName = "ki-textract-demo-docs" +const documentName = "simple-document-image.jpg" + +exports.handler = async (event, context) => { + let textractParams = { + Document: { + S3Object: { + Bucket: s3BucketName, + Name: documentName, + } + }, + }; + try { + let response = await textract.detectDocumentText(params).promise(); + console.log(JSON.stringify(response),null,2) + } catch (e) { + console.log("Error: ", e) + } +} \ No newline at end of file diff --git a/nodejs/03-analyze-expense-local.js b/nodejs/03-analyze-expense-local.js new file mode 100644 index 0000000..b3057e1 --- /dev/null +++ b/nodejs/03-analyze-expense-local.js @@ -0,0 +1,21 @@ +/*Example showing analyzing expense with document on local machine.*/ + +const aws = require('aws-sdk'); +/*Initializing Textract from AWS SDK JS*/ +const textract = new aws.Textract({ apiVersion: "2018-06-27" }); +/*File system package for importing images and converting the image data to ByteArray */ +const fs = require('fs'); + +exports.handler = async(event, context) => { + let textractParams = { + Document: { + Bytes: fs.readFileSync("receipt.jfif") + }, + }; + try { + let response = await textract.analyzeExpense(params).promise(); + console.log(JSON.stringify(response),null,2) + }catch(e){ + console.log("Error: ",e) + } +} \ No newline at end of file diff --git a/nodejs/04-analyze-expense-s3.js b/nodejs/04-analyze-expense-s3.js new file mode 100644 index 0000000..6d648ce --- /dev/null +++ b/nodejs/04-analyze-expense-s3.js @@ -0,0 +1,24 @@ +/*Example showing analyzing expense with document on AWS S3 bucket.*/ + +const aws = require('aws-sdk'); +/*Initializing Textract from AWS SDK JS*/ +const textract = new aws.Textract({ apiVersion: "2018-06-27" }); +const s3BucketName = "ki-textract-demo-docs" +const documentName = "receipt.jfif" + +exports.handler = async (event, context) => { + let textractParams = { + Document: { + S3Object: { + Bucket: s3BucketName, + Name: documentName, + } + }, + }; + try { + let response = await textract.analyzeExpense(params).promise(); + console.log(JSON.stringify(response),null,2) + } catch (e) { + console.log("Error: ", e) + } +} \ No newline at end of file diff --git a/nodejs/README.md b/nodejs/README.md new file mode 100644 index 0000000..a2949c8 --- /dev/null +++ b/nodejs/README.md @@ -0,0 +1,6 @@ +# Textract NodeJS Examples + +| Argument | Description | +| ----------------------------------------------------------- | ---------------------------------------------------------- | +| [01-detect-text-local.js](./01-detect-text-local.js) | Example showing processing a document on local machine. | +| [02-detect-text-s3.js](./02-detect-text-s3.js) | Example showing processing a document in Amazon S3 bucket. | diff --git a/nodejs/receipt.jfif b/nodejs/receipt.jfif new file mode 100644 index 0000000..71b2202 Binary files /dev/null and b/nodejs/receipt.jfif differ diff --git a/nodejs/simple-document-image.jpg b/nodejs/simple-document-image.jpg new file mode 100644 index 0000000..cd5b94c Binary files /dev/null and b/nodejs/simple-document-image.jpg differ