How to Download Completed Document

Get a protected PDF copy of document after they've been completed by all signers using webhook notifications.

How to Download Completed document

Problem

You need to automatically download protected PDF copies of document immediately after they've been completed by all signers, rather than manually checking document status or polling the API.

Prerequisites

💡

Quick Check Alternative: For simple use cases or testing, you can download completed documents without webhooks by periodically checking document status using the Get Document Status and downloading when status is document.completed.

Solution

Step 1: Configure Webhook for PDF Ready Event

Set up a webhook subscription to receive document_completed_pdf_ready events:

  1. Using Developer Dashboard:

    • Navigate to API Configuration
    • Click "Create webhook" in the Webhooks section
    • Add your webhook endpoint URL
    • Check "PDF of completed document available for download" under "Subscribe to events"
    • Save the configuration
  2. Using API:

    curl -X POST "https://api.pandadoc.com/public/v1/webhook-subscriptions" \
      -H "Authorization: Bearer YOUR_API_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{
        "name": "PDF Download Webhook",
        "url": "https://your-domain.com/webhook-handler",
        "triggers": ["document_completed_pdf_ready"],
        "active": true
      }'

Step 2: Handle the Webhook Event

Process the incoming webhook to extract the document ID:

[
  {
    "event": "document_completed_pdf_ready",
    "data": {
      "id": "tKoqk92d2jiVuxUQH8i9iB",
      "name": "Contract Agreement",
      "status": "document.completed",
      ...
    }
  }
]

Extract the document id from the data object for use in the download request.

Step 3: Choose Download Method

Select the appropriate endpoint based on your needs:

  • Protected PDF (recommended): /download-protected - Returns digitally sealed PDF
  • Regular PDF: /download - Supports watermarks and customization options

Step 4: Download the PDF

Use the document ID to download the PDF with your chosen method:

For Protected PDF (recommended):

curl -X GET "https://api.pandadoc.com/public/v1/documents/{document_id}/download-protected" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -o "completed-document.pdf"

For Regular PDF:

curl -X GET "https://api.pandadoc.com/public/v1/documents/{document_id}/download" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -o "completed-document.pdf"

Replace {document_id} with the document ID from the webhook payload.

📝

Note: The /download-protected endpoint always returns the same digitally sealed PDF file, while /download allows for watermark customization but provides a less secure file.

Verification

To confirm your setup is working:

  1. Test webhook delivery: Create a test document and complete it to trigger the webhook
  2. Check webhook history: Monitor delivery status in the Webhooks History tab
  3. Verify PDF download: Confirm your application successfully downloads and processes the PDF file
  4. Test file integrity: Ensure the downloaded PDF opens correctly and contains expected content

Troubleshooting

Common issues and solutions:

Webhook not received:

  • Verify webhook subscription is active and configured for document_completed_pdf_ready
  • Check endpoint accessibility
  • See How to Debug and Monitor Webhooks for detailed troubleshooting

PDF download fails:

  • Confirm document ID is correctly extracted from webhook payload
  • Verify API authentication is valid
  • Check that document is actually completed (status: "document.completed")

File corruption or access issues:

  • Ensure proper binary handling when saving PDF files
  • Verify sufficient disk space and write permissions
  • Check network connectivity for complete file transfer

Related