In this tutorial, we will show you how to extract a table with text from PDF in JavaScript using PDF.co Web API. Below is the image of the source PDF and the extracted table with text output in JSON format.

Source and Output
Source PDF and Extracted Table with Text Output

Step 1: Source Code and Template

To begin, open the Visual Studio Code or your favorite editor and save the following files.

JavaScript File Folder

Step 2: Install Requests Module

To install the requests module, kindly type the npm install requests in your terminal. We will use this requests module for file upload.

Step 3: Insert API Key

In line 12, insert your API key inside the double quote. You can get the API key in your PDF.co dashboard here.

PDF.co API Key

Step 4: Source and Destination File

In line 15, add your source PDF file and type your desired output file name in line 19. Aside from JSON output, you can also extract tables with text in CSV and XML formats.

Source and Destination File

Step 5: Add Template

In line 96, add the template name. The Document Parser supports both JSON and YML template formats.

For more details about Document Parser Template, check out this page.

Add Template

Step 6: Run JavaScript Program

To run the program, simply type node file.js in the terminal.

Step 7: Extract Table with Text Demo

Here’s a quick demo to extract a table with text from the PDF.

Extract tables with Text Demo
Extract tables with Text Demo

In this tutorial, you learned how to extract a table with text from PDF in JavaScript using PDF.co Web API. You learned how to set up the JavaScript source code to run the program successfully. You also learned how the PDF.co Document Parser parses the table with text from PDF.

Related Pages:

Related Samples: