This sample project helps you get started with the PDF Tools Extract Node.js SDK.
The sample JS scripts illustrate how to perform PDF-related actions (extracting content of PDF in user friendly structured format) using the SDK.
The sample application has the following requirements:
- Node.js : Version 10.13 or above. Node installation instructions can be found here.
The credentials file and corresponding private key file for the samples is pdftools-api-credentials.json and private.key
respectively. Before the samples can be run, replace both the files with the ones present in the zip file received via Beta Program Access workflow.
The SDK also supports providing the authentication credentials at runtime, without storing them in a config file. Please refer this section to know more.
Run the following command to build the project:
npm install
Note that the PDF Tools Extract SDK is listed as a dependency in the package.json and will be downloaded automatically.
For logging, this SDK uses the log4js API .
Upon running, the SDK searches for a file config/pdftools-sdk-log4js-config.json in the working directory, and reads the
logging properties from there. If no configuration file is provided, default logging, i.e. logging INFO logs to the console is enabled. The clients can change the logging settings as per their needs.
The output of SDK extract operation is Zip package. The Zip package consists of following:
- The structuredData.json file with the extracted content & PDF element structure. See the JSON schema.
- A renditions folder(s) containing renditions for each element type selected as input. The folder name is either “tables” or “figures” depending on your specified element type. Each folder contains renditions with filenames that correspond to the element information in the JSON file.
The following sub-sections describe how to run the samples. Prior to running the samples, check that the configuration file is set up as described above and that the project has been built.
The samples code is available under the src folder. Test
files used by the samples can be found in the resources folder. When executed, all samples create an output
child folder under the project root directory to store their results.
These samples illustrate how to extract PDF elements from PDF. Refer to the documentation of ExtractPDFOperation to see the list of inputs.
The sample script extract-text-info-from-pdf.js extracts text elements from PDF Document.
node src/extractpdf/extract-text-info-from-pdf.js
The sample script extract-text-table-info-from-pdf.js extracts text, table elements from PDF Document.
node src/extractpdf/extract-text-table-info-from-pdf.js
The sample script extract-text-table-info-with-tables-renditions-from-pdf.js extracts text, table elements along with table renditions
from PDF Document. Note that the output is a zip containing the structured information along with renditions as described
in section.
node src/extractpdf/extract-text-table-info-with-tables-renditions-from-pdf.js
The sample script extract-text-table-info-with-figures-tables-renditions-from-pdf.js extracts text, table elements along with figure
and table element's renditions from PDF Document. Note that the output is a zip containing the structured information
along with renditions as described in section.
node src/extractpdf/extract-text-table-info-with-figures-tables-renditions-from-pdf.js
The sample script extract-text-info-from-pdf-with-inmem-auth-cred.js extracts text elements from PDF Document.
This sample highlights how to provide in-memory auth credentials for performing an operation.
This enables the clients to fetch the credentials from a secret server during runtime, instead of storing them in a file.
node src/extractpdf/extract-text-info-from-pdf-with-inmem-auth-cred.js
Extract Text, Table Elements and bounding boxes for Characters present in text blocks with Renditions of Table Elements
The sample script extract-text-table-info-with-char-bounds-from-pdf.js extracts text, table elements, bounding boxes for characters present in text blocks and table element's renditions from PDF Document.
Note that the output is a zip containing the structured information along with renditions as described in section.
node src/extractpdf/extract-text-table-info-with-char-bounds-from-pdf.js
The sample script extract-text-table-info-with-tables-structure-from-pdf.js extracts text, table elements, table structures as CSV and table element's renditions from PDF Document. Note that the output is a zip containing the structured information along with renditions as described in section.
node src/extractpdf/extract-text-table-info-with-tables-structure-from-pdf.js
Contributions are welcome! Read the Contributing Guide for more information.
This project is licensed under the MIT License. See LICENSE for more information.