Skip to main content

How to Generate PDFs from Google Docs with the API

This guide walks you through everything — from getting your API key to generating your first PDF. No UI needed. Just HTTP requests.

~10 min read 5 steps

Prerequisites

  • A Google Account with access to Google Docs
  • An API key from Docs Render API (get one here)
  • A way to make HTTP requests (curl, Postman, or any programming language)
1

Purchase API Credits & Get Your API Key

Visit the pricing section on the home page and choose a credit pack. After a successful Stripe checkout, you'll immediately see your API key on the success page.

Important: Copy your API key immediately. It is only shown once for security reasons. Store it securely (e.g., in an environment variable).

Your API key will look like this:

dra_k_a1b2c3d4e5f6g7h8i9j0...
2

Connect Your Google Account

After receiving your API key, you'll be prompted to connect your Google account. This authorizes the API to read your Google Docs templates. We only request read access — we never modify your documents.

Connect Google Account
GET https://docs-render-api-307616438192.europe-west1.run.app/auth/google/start
x-api-key: YOUR_API_KEY

# This redirects you to Google's OAuth consent screen.
# After granting access, you'll be redirected back automatically.

💡 You only need to do this once per API key. The authorization persists until you revoke it.

3

Create Your Google Doc Template

Open Google Docs and design your document exactly how you want the final PDF to look. Use double curly braces for any fields that should be dynamically replaced.

Example Template

INVOICE

Invoice #: {{invoice_number}}

Date: {{date}}

Bill To: {{customer_name}}

Description: {{description}}

Total: {{total_amount}}

Tip: All formatting in Google Docs is preserved — fonts, colors, tables, images, headers/footers. Design it once, generate PDFs forever.

4

Get Your Google Doc Template ID

Open your template in Google Docs and copy the document ID from the URL. It's the long string between /d/ and /edit.

Google Doc URL:

https://docs.google.com/document/d/1qW1eY8eK9i8tO_ABcDeFgHiJkLmNoPqRsTuVwXyZ/edit

↑ The highlighted part is your template ID

Optional: Register a Template Alias

Instead of using the long document ID, you can register a short, memorable alias:

Register Template Alias
curl -X POST https://docs-render-api-307616438192.europe-west1.run.app/templates \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "alias": "invoice_v1",
    "google_doc_id": "1qW1eY8eK9i8tO_ABcDeFgHiJkLmNoPqRsTuVwXyZ"
  }'

Now you can use invoice_v1 instead of the long document ID in your API calls.

5

Generate Your First PDF

Make a POST request to the /docs/render endpoint with your template ID (or alias) and the variables to fill in. The API returns a PDF file stream.

curl -X POST https://docs-render-api-307616438192.europe-west1.run.app/docs/render \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "template": "invoice_v1",
    "variables": {
      "invoice_number": "INV-2024-001",
      "date": "February 12, 2026",
      "customer_name": "Acme Corp",
      "description": "Web Development Services",
      "total_amount": "$5,000.00"
    }
  }' \
  --output invoice.pdf

# ✅ invoice.pdf is saved to your current directory

That's it! The API returns a standard application/pdf binary stream. Save it to a file, attach it to an email, upload it to S3 — whatever your workflow needs.

Frequently Asked Questions

Do I need a Google Workspace account?

No. Any free Google account with access to Google Docs works. The API reads your templates via standard Google OAuth.

Can I use the same template for different customers?

Absolutely. That's the whole point. Create one template with {{placeholders}}, then call the API with different variables each time to generate unique PDFs.

What format does the API return?

The API returns a standard application/pdf binary stream. You can save it as a file, attach it to an email, upload it to cloud storage, or stream it directly to a user's browser.

Do credits expire?

No. Credits never expire. One credit = one PDF generation. Buy credits whenever you need them.

Can I use this with Zapier, Make, or n8n?

Yes. The API is a standard REST endpoint. Any tool that can make HTTP requests can use it — including Zapier (with a webhook action), Make, n8n, Retool, and more.