This project provides two implementations of a contract note parser that uses OpenAI's GPT-4 to extract structured data from PDF contract notes:
- A Node.js implementation for local processing
- A Google Apps Script implementation for Google Sheets integration
- Node.js (v14 or higher)
- Yarn package manager
- OpenAI API key
- Google account
- Google Drive access
- OpenAI API key
- Clone the repository:
git clone <repository-url>
cd docparse- Install dependencies:
yarn install- Create a
.envfile in the root directory:
OPENAI_API_KEY=your_api_key_here
-
Place your PDF contract note in the project directory or update the path in
src/main.ts -
Run the parser:
yarn startThe extracted data will be saved to extracted_data.json in the project directory.
-
Create a new Google Sheet
-
Go to Extensions > Apps Script
-
Delete any code in the script editor and paste the contents of
src/contractParser.gs -
Replace the API key in the script:
const OPENAI_API_KEY = 'your_api_key_here';-
Save the script (File > Save)
-
Enable required services:
- Click on "Services" (+ icon)
- Add the following services:
- Drive API
- Google Sheets API
-
Authorize the script:
- Click the "Run" button
- Grant necessary permissions when prompted
Simply run the script and it will process the PDF file specified in the code:
yarn start- Open your Google Sheet
- Look for the "Contract Parser" menu in the toolbar
- Click "Contract Parser" > "Process PDF"
- Select your PDF file from Google Drive
- Wait for the processing to complete
- The extracted data will appear in a new sheet named "Extracted Data"
The parser extracts the following information from contract notes:
- Trade details
- Quantities
- Prices
- Other relevant table data
The data is structured in a JSON format and, in the Google Sheets version, is presented in a two-column format:
- Column A: Field names
- Column B: Extracted values
-
PDF Text Extraction Issues
- Ensure the PDF is not scanned as an image
- Check if the PDF is not password protected
- Verify the PDF is readable and not corrupted
-
API Key Issues
- Verify your OpenAI API key is correct
- Check if you have sufficient credits in your OpenAI account
- Ensure the API key has not expired
-
Google Apps Script Issues
- Make sure all required services are enabled
- Check if you have necessary permissions for the Google Sheet
- Verify the PDF is accessible to the script
- "No PDF file uploaded" - Make sure you've selected a PDF file
- "Error processing PDF" - Check the PDF format and accessibility
- "API Error" - Verify your OpenAI API key and internet connection
- Never commit your
.envfile or API keys to version control - Keep your OpenAI API key secure and don't share it
- Regularly rotate your API keys
- Be cautious when sharing Google Sheets with the script
Feel free to submit issues and enhancement requests!
This project is licensed under the MIT License - see the LICENSE file for details.