Help Center

How-tos
>Save edited PDF submissions to Supabase

How to save edited PDF submissions to Supabase

Profile picture of Benjamin André-Micolon

You have added SimplePDF to your app, or your AI Agent and you would like to store the PDF submissions in your Supabase Storage.

You could for example by trying to:

  • Automate further the handling of the submissions: for example extracting the data from the forms to process them
  • Store the PDF in a vector store to offer semantic search or automatically detect duplicates or similarities in the submitted PDF

For this tutorial we'll be using two PRO features from SimplePDF:

  1. The webhooks integration - together with Supabase Edge Functions

The code for the Supabase Edge function can be found here

  1. The S3 integration - together with Supabase Storage

Configuring Supabase Storage for the PDF submissions

In this section we'll walk you through setting up Supabase Storage as a storage for the edited PDF submissions (and documents) instead of SimplePDF's default storage.

  1. Head over to Storage in your Supabase project and click New bucket

  2. Name your bucket, keep it private (do not toggle Public bucket) and then click Save

Create a bucket in Supabase storage

  1. In the Storage settings, create a new S3 Access Keys

Create a S3 Access Key in Supabase

  1. Head over to your SimplePDF account and configure the S3 storage as follows:

You can find a step-by-step here

Endpoint: <COPIED the endpoint in the S3 Connection in Supabase Storage settings>
Path-style: <TOGGLE enabled>
Region: <SELECT the region visible in the S3 Connection in Supabase Storage settings>
Bucket: <ENTER the name of the bucket: in our example we used "pdf">
Access Key ID: <PASTE the value you get in the step 3. above>
Secret Access Key: <PASTE the value you get in the step 3. above>

Configuring S3 in SimplePDF

  1. Click Update and head over to your Supabase storage and notice that a new file has been automatically added: this confirms that the configuration is ready!

Feel free to delete this file: you won't need it anymore

S3 configuration completed in Supabase

Configuring a new Supabase Table to store the PDF submissions metadata

In this section we'll be creating a new table to store the metadata we receive from SimplePDF for each new submissions. We'll be using Supabase Edge Functions to insert the data in the table.

If you want to jump ahead and skip the tutorial, you can see the full source code, table definition and pre-requisites over here

  1. Head over to Database > Tables and create a new table - we'll name it simplepdf_submissions

  2. Define the following schema: You can see the schema defined in SQL in Github over here

  • id: int8 - Primary
  • document_name: text
  • document_id: text
  • submission_id: text
  • submission_bucket_path: text
  • context: jsonb

Created table in Supabase

  1. Deploy the read-made Edge Function we have created for you: source code on Github
npm i
npm run deploy
  1. Create a new RLS policy to allow this edge function to insert rows into the simplepdf_submissions table:

For production use, we recommend a stricter RLS policy or to authenticate the webhooks calls by passing an authorization header from SimplePDF's end

alter policy "Allow edge function to insert into simplepdf_submissions"
  on "public"."simplepdf_submissions"
  to anon
  with check (true);

Created RLS policy

  1. Copy the URL of the simplepdf-webhooks Edge Function in the Edge Functions section in supabase

Copy edge function URL

  1. Head over to SimplePDF and configure the webhooks to point to your deployed simplepdf-webhooks function

You can find a step-by-step here

Configured webhooks in SimplePDF

That's it! The integration is ready! Storing edited PDFs in Supabase Storage and saving events (and metadata) using Supabase Edge Functions about edited PDF submissions in a table!

First edited PDF submission in Supabase

If you have any questions, feel free to reach out to support@simplepdf.com

You may also be interested in

?