Drive2PDF API

Generate high-quality PDF documents from Google Docs and Sheets templates with advanced data insertion, conditional sections, repeating tables, and dynamic images.

Key Features

  • Document Templates — Use Google Docs with placeholders for text, images, conditional sections, and repeating tables.
  • Sheet Templates — Use Google Sheets with dynamic cell data, row/column visibility control, and multi-tab export.
  • Rich Content — Support for styled text, hyperlinks, and dynamic images.
  • PDF Customization — Add watermarks, metadata, and control page size/orientation.
  • Secure Storage — Generated PDFs are stored securely and accessible via unique URLs for 24 hours (1-day TTL).

Authentication

All API requests require authentication using your API key. Include the key in the request header:

Header Value Required
api_key Your API key Required
Content-Type application/json Required

Getting Your API Key

Your API key is available in your Drive2PDF dashboard. Keep it secure and never expose it in client-side code.

Base URL

All API requests should be made to:

https://api.drive2pdf.com

Document Template Language

Drive2PDF uses a powerful template language for Google Docs that allows you to define dynamic content using placeholders, conditional sections, and repeating tables.

Page Setup

Page orientation, size, and margins are configured directly in your Google Doc template via File → Page setup. The PDF will use these settings automatically.

Text Placeholders

Text placeholders are defined using double curly braces: {{placeholder_name}}. These are replaced with the corresponding values from your API request.

Template Example

Dear {{customer_name}},

Thank you for your purchase on {{date}}. Your order #{{order_id}} has been confirmed.

API Data

{
  "data": [
    { "key": "customer_name", "value": "John Doe", "type": "text" },
    { "key": "date", "value": "January 22, 2026", "type": "text" },
    { "key": "order_id", "value": "ORD-12345", "type": "text" }
  ]
}

Key Matching

Keys are case-insensitive. {{Customer_Name}} and {{customer_name}} will both match the key "customer_name".

Conditional Sections

Conditional sections allow you to show or hide entire blocks of content based on a boolean value. Define sections with opening and closing tags:

Template Syntax

{{disclaimer}}
This section will only appear if the "disclaimer" key has show: true.
{{/disclaimer}}

API Data (Hide Section)

{
  "data": [
    { "key": "disclaimer", "show": false, "type": "section" }
  ]
}

If the section key is not provided in the data, the section content will be kept (shown) by default.

Repeating Tables

Repeating tables allow you to dynamically generate rows based on an array of data. Only the rows containing placeholders with dotted field notation (e.g., {{member.name}}) will be repeated for each item in the array.

Template Structure

Create a table with a header row containing {{table_key}} and data rows with {{table_key.field}} placeholders:

Name {{member}} Role Age
{{member.name}} {{member.role}} {{member.age}}

API Data

{
  "data": [
    {
      "key": "member",
      "type": "table",
      "value": [
        { "name": "Sarah Mitchell", "role": "CEO", "age": "34" },
        { "name": "James Chen", "role": "CTO", "age": "29" },
        { "name": "Emily Rodriguez", "role": "Designer", "age": "31" }
      ]
    }
  ]
}

Advanced Table Features

  • Multi-row headers/footers: Rows without dotted field placeholders are preserved as static headers or footers.
  • Row styling: Background colors, text styles, and borders from template rows are preserved in generated rows.
  • Independent placeholders: Regular placeholders (not using dotted notation) in header/footer rows work normally and are replaced with their values.

Table Requirements

The {{member}} identifier must be placed in a header row cell. All field placeholders must use the dotted notation: {{table_key.field_name}}.

Images

To replace images in your template, insert a placeholder image in Google Docs and set its Alt Text title to the key name. The API will replace it with the image from the provided URL.

Setup Steps

  1. Insert a placeholder image in your Google Doc
  2. Right-click the image → Alt Text
  3. Set the Title to your key (e.g., logo)

Image placeholder example showing Alt Text menu

API Data

{
  "data": [
    {
      "key": "logo",
      "value": "https://example.com/logo.png",
      "type": "image"
    }
  ]
}

Advanced: Image with Link

{
  "key": "logo",
  "value": "https://example.com/logo.png",
  "link": "https://example.com",
  "type": "image"
}

Images in Tables

For images inside repeating tables, use the dotted notation for the Alt Text title:

// Alt Text title: member.photo

"value": [
  { "photo": "https://example.com/sarah.jpg", "name": "Sarah" },
  { "photo": "https://example.com/james.jpg", "name": "James" }
]

Tip: Images as Buttons

Images with links can be used as clickable buttons in your PDF! Add the link property to make the image clickable.

Rich Text

Rich text allows you to insert styled text with bold, italic, colors, and more. Use the richtext type with an array of text segments.

API Data

{
  "key": "features",
  "type": "richtext",
  "value": [
    { "text": "Doc to PDF", "bold": true },
    { "text": ": Generate PDFs from Google Docs\n" },
    { "text": "Sheet to PDF", "bold": true, "color": "#6366f1" },
    { "text": ": Generate PDFs from Google Sheets" }
  ]
}

Available Style Properties

Property Type Description
text string The text content
bold boolean Bold text
italic boolean Italic text
underline boolean Underlined text
strikethrough boolean Strikethrough text
color string Text color (hex, e.g., #FF0000)
highlight string Background color (hex)
size number Font size in points
url string Make text a hyperlink

Sheets Templates

Google Sheets templates work differently from Docs. Instead of placeholders, you provide cell coordinates and data to insert. You can also control row/column visibility and export multiple tabs.

Sheet Organization

Each sheet tab in your spreadsheet has a unique GID (sheet ID). You can:

  • Add data to any cell in any GID
  • Hide or show rows/columns in any GID
  • Export specific GIDs to PDF
  • Merge multiple GIDs into a single PDF

Finding the GID

The GID is visible in the spreadsheet URL after #gid=. The first tab is always gid=0.

Data Insertion

Specify a target cell and provide a 2D array of values to insert starting from that cell.

{
  "data": [
    {
      "targetCell": "B2",
      "gid": 0,
      "content": [
        ["Name", "Amount", "Status"],
        ["Order A", 150.00, true],
        ["Order B", 299.99, false]
      ]
    }
  ]
}
Field Type Description
targetCell string Starting cell in A1 notation (e.g., "A1", "B2"). Use the gid field to specify the sheet.
gid number Sheet tab ID (default: 0)
content array 2D array of values (strings, numbers, booleans)

Image Links in Data

You can pass image URLs directly in your data array. Google Sheets will display them inline using the =IMAGE() formula when rendered.

Row/Column Visibility

Control the visibility of rows and columns dynamically. This is useful for hiding empty rows or conditional content.

{
  "visibility": [
    {
      "dimension": "row",
      "start": 10,
      "quantity": 5,
      "hide": true,
      "gid": 0
    },
    {
      "dimension": "column",
      "start": 4,
      "end": 6,
      "hide": true
    }
  ]
}
Field Type Description
dimension string "row" or "column"
start number Starting index (1-based)
end number Ending index (1-based, alternative to quantity)
quantity number Number of rows/columns (alternative to end)
hide boolean true to hide, false to show
gid number Sheet tab ID (default: 0)

Export Options

Control how the sheet is exported to PDF, including page size, orientation, margins, and which tabs to include.

Field Type Default Description
gid number | array 0 Tab(s) to export
name string | array Auto Output filename(s)
size string "A4" Page size (e.g., "letter", "legal")
portrait boolean true Portrait orientation
margins string "0" Margins in inches: "0.5" or "0.5,0.25,0.5,0.25"
merge boolean true Merge multiple tabs into one PDF

API Reference

/v1/pdf Endpoint

POST /v1/pdf

Generate a PDF from a template. The template type (Doc or Sheet) is determined automatically based on the template configuration.

Common Parameters

These parameters apply to both Document and Sheet templates:

Field Type Required Description
template_id string Required Your template ID (from your Drive2PDF dashboard, not the Google Drive file ID)
watermark boolean Optional Enable watermark (uses template/user default)
watermark_image_url string Optional Override watermark image URL
watermark_opacity number Optional Watermark opacity (0.0 to 1.0)
metadata object Optional PDF metadata object (see fields below)
base64 boolean Optional Include base64-encoded PDF in response

Metadata Object Fields

Field Type Description
Title string PDF title
Author string PDF author
Subject string PDF subject
Keywords string | array Keywords (comma-separated string or array)
Producer string PDF producer (default: "drive2pdf.com")
Creator string PDF creator (default: "drive2pdf.com")
CreationDate string Creation date (ISO 8601 format)
ModificationDate string Modification date (ISO 8601 format)

Document Parameters

Additional parameters for Document (Google Docs) templates:

Field Type Description
data array Array of replacement objects (see Template Language)
name string Output filename (default: "document.pdf")

Data Object Types

Type Required Fields Optional Fields
text key, value
image key, value (URL) link
richtext key, value (array)
link key, value (URL) caption, color, underline
section key show (boolean)
table key, value (array of objects)

Sheet Parameters

Additional parameters for Sheet (Google Sheets) templates:

Field Type Description
data array Array of cell update objects
visibility array Array of row/column visibility changes
gid number | array Sheet tab ID(s) to export (default: 0)
name string | array Output filename(s)
size string Page size (default: "A4")
portrait boolean Portrait orientation (default: true)
margins string Margins in inches (default: "0")
merge boolean Merge tabs into one PDF (default: true)

Response

Success Response (200)

{
  "urls": ["https://pdf.drive2pdf.com/pdfs/.../document.pdf"]
}

With base64: true

{
  "urls": ["https://pdf.drive2pdf.com/pdfs/.../document.pdf"],
  "base64": ["JVBERi0xLjQKJ..."]
}

Response Headers

Header Description
X-Request-Id Unique request ID for debugging
X-Documents-Limit Your remaining document quota
X-RateLimit-Quota Max requests per minute allowed
X-RateLimit-Remaining Requests remaining in current window
X-RateLimit-Reset Timestamp (ms) when rate limit resets

Error Responses

All errors return a JSON object with code and message:

{
  "code": "ERROR_CODE",
  "message": "Human-readable description"
}
Status Code Description
400 INVALID_REQUEST_PAYLOAD Invalid or malformed request data
400 TEMPLATE_NOT_DEPLOYED Template has not been deployed
401 API_KEY_INVALID Invalid or missing API key
401 NO_REFRESH_TOKEN User OAuth token not configured
402 QUOTA_EXCEEDED Document quota exhausted
408 REQUEST_TIMEOUT Processing exceeded time limit
429 RATE_LIMIT_CONCURRENT_EXCEEDED Too many concurrent requests
429 RATE_LIMIT_PER_MINUTE_EXCEEDED Too many requests per minute
500 INTERNAL_SERVER_ERROR Unexpected server error
503 SERVICE_CAPACITY_EXCEEDED Service at capacity, retry later

Examples

Document with Text and Image

cURL
curl -X POST https://api.drive2pdf.com/v1/pdf \
  -H "api_key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "template_id": "tpl-123",
    "data": [
      { "key": "name", "value": "John Doe", "type": "text" },
      { "key": "date", "value": "January 22, 2026", "type": "text" },
      { "key": "signature", "value": "https://example.com/sig.png", "type": "image" }
    ],
    "name": "certificate",
    "watermark": true,
    "metadata": {
      "Title": "Certificate of Completion",
      "Author": "Acme University"
    }
  }'

Sheet with Multiple Tabs

cURL
curl -X POST https://api.drive2pdf.com/v1/pdf \
  -H "api_key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "template_id": "tpl-456",
    "data": [
      { "targetCell": "B2", "content": [["Monthly Report"]], "gid": 0 },
      { "targetCell": "A5", "content": [[1500, 2300, 1800]], "gid": 0 }
    ],
    "visibility": [
      { "dimension": "row", "start": 10, "quantity": 5, "hide": true }
    ],
    "gid": [0, 58736200],
    "name": ["summary", "details"],
    "size": "letter",
    "portrait": false,
    "margins": "0.5",
    "merge": false
  }'

Document with Repeating Table

cURL
curl -X POST https://api.drive2pdf.com/v1/pdf \
  -H "api_key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "template_id": "tpl-789",
    "data": [
      { "key": "company_name", "value": "Acme Corp", "type": "text" },
      { "key": "report_date", "value": "Q4 2025", "type": "text" },
      {
        "key": "employee",
        "type": "table",
        "value": [
          { "name": "Alice Johnson", "department": "Engineering", "salary": "$95,000" },
          { "name": "Bob Smith", "department": "Marketing", "salary": "$78,000" },
          { "name": "Carol White", "department": "Sales", "salary": "$82,000" }
        ]
      },
      { "key": "total_employees", "value": "3", "type": "text" }
    ],
    "name": "employee_report"
  }'