API Tutorial

Webhook Integration for PDF Workflows

Stop generating PDFs manually. Webhooks let you trigger PDF creation automatically — when a form is submitted, a page is updated, or a schedule fires. Connect Pretty PDF to your existing tools and workflows.

API Tutorial

Event-driven PDF generation

Replace manual scripts and polling with a push-based architecture that generates PDFs the moment something happens.

Instead of polling an endpoint or running scripts on a timer, webhooks push events to your handler the instant something happens. A form is submitted, a CMS page is published, a deployment finishes — the source system sends an HTTP POST to your webhook URL with the event details.

Pair this with the Pretty PDF API: the incoming webhook triggers your handler, which extracts the URL or HTML content from the event payload and calls the Pretty PDF API to generate a PDF. The result is a fully automated, zero-touch PDF workflow. No cron jobs to maintain, no scripts to babysit, no manual intervention required.

This pattern works with any system that can send HTTP webhooks — form builders, CMSes, CI/CD pipelines, email services, RSS readers, monitoring tools, and hundreds of SaaS products that support outbound webhooks.

API Tutorial

Common trigger events

Any system event that produces content worth archiving or distributing as a PDF can serve as a webhook trigger.

Form submission

A contact form, survey, or application is submitted. Your webhook handler receives the submission data, formats it as HTML or fetches a confirmation page URL, and calls the Pretty PDF API to generate a PDF receipt or record. Attach the PDF to a confirmation email or store it for compliance.

Page update

A CMS page is published or updated. The webhook fires with the page URL, and your handler calls the Pretty PDF API to create a snapshot. Useful for maintaining PDF mirrors of documentation, policy pages, or knowledge base articles that need to stay current.

Schedule

A cron job or scheduled trigger fires at a set interval — daily, weekly, or monthly. Your handler calls the Pretty PDF API with a list of URLs to archive. Ideal for compliance snapshots, recurring reports, and periodic documentation backups.

Email receipt

An email arrives at a designated address. A service like Zapier or Mailgun parses the email and triggers your webhook with the email body. Your handler converts the email content to a PDF for archival or forwarding as an attachment.

New RSS item

A new blog post or article appears in an RSS feed. Your automation platform detects the new item and sends the article URL to your webhook handler, which calls the Pretty PDF API to generate a PDF archive copy. Build a searchable PDF library of content from any RSS source.

Deployment

A CI/CD pipeline completes a deployment. The pipeline triggers a webhook that calls the Pretty PDF API with your documentation URLs to generate updated PDF versions of your docs. Attach the PDFs to release artifacts so every release ships with current offline documentation.

API Tutorial

Integration with Zapier

Connect Pretty PDF to 6,000+ apps with Zapier's no-code automation platform. No server required.

Step-by-step Zapier setup

Zapier connects a trigger (something happens) to an action (do something about it). To generate PDFs automatically, you create a Zap with two steps:

  • Step 1: Choose your trigger. Select the app where the event originates — for example, "New form submission in Typeform," "New row in Google Sheets," or "New item in RSS feed." Configure the trigger to fire on the specific event you want to capture.
  • Step 2: Add a Webhooks by Zapier action. Select "Webhooks by Zapier" as the action app and choose "POST" as the action event. Set the URL to https://api.prettypdfprinter.com/v1/generate/url. Set the payload type to JSON and add your API key in a custom header: X-API-Key: your_api_key. Map the URL or HTML from the trigger step into the request body.
  • Step 3: Handle the output. Add a third step to store or distribute the generated PDF — upload to Google Drive, attach to an email via Gmail, post to a Slack channel, or save to Dropbox. Zapier passes the PDF binary from the webhook response to the storage action.

Once activated, the Zap runs every time the trigger fires. A new form submission, a new spreadsheet row, a new RSS item — each one automatically generates a PDF and stores it in your chosen destination.

API Tutorial

Integration with Make (Integromat)

Build visual multi-step PDF workflows with Make's drag-and-drop scenario builder.

Module chain overview

Make (formerly Integromat) uses a visual scenario builder where you connect modules in a chain. Each module processes data and passes it to the next. For PDF generation, the typical chain looks like this:

  • Trigger module: Watches for an event in your source app — a new form response in Google Forms, a page update in Notion, a new message in Slack, or any of Make's 1,500+ app integrations.
  • HTTP module: Sends a POST request to the Pretty PDF API. Configure the URL as https://api.prettypdfprinter.com/v1/generate/url, add the X-API-Key header, and map the URL or HTML content from the trigger module into the JSON body.
  • Storage or notification module: Takes the PDF response and stores it (Google Drive, Dropbox, OneDrive) or distributes it (email, Slack, Microsoft Teams). You can add multiple output modules to store and notify simultaneously.

Make's visual builder makes complex multi-step flows accessible without writing code. You can add conditional logic (only generate PDFs for certain form values), error handling (retry on failure, alert on repeated failures), and parallel branches (store the PDF and send a notification at the same time).

Make's free tier includes 1,000 operations per month, which may be sufficient for low-volume workflows. The HTTP module for calling the Pretty PDF API is available on all plans.

API Tutorial

Integration with n8n (self-hosted)

For teams that want full control over their automation infrastructure, n8n runs on your own servers.

Self-hosted webhook workflows

n8n is an open-source workflow automation tool that you can self-host on your own infrastructure. This means your webhook payloads, PDF content, and workflow logic never leave your network — except for the API call to Pretty PDF itself.

  • Webhook node: n8n exposes a webhook URL that receives incoming POST requests from your trigger source. Configure the webhook node to listen on a custom path and parse the incoming JSON payload.
  • HTTP Request node: Calls the Pretty PDF API with the URL or HTML extracted from the webhook payload. Set the method to POST, the URL to https://api.prettypdfprinter.com/v1/generate/url, and include the X-API-Key header. Map the content from the webhook node into the request body.
  • Output node: Stores the generated PDF on your local filesystem, uploads it to S3, sends it via email, or posts it to your internal tools. Since n8n is self-hosted, you can write directly to local storage or internal APIs that are not accessible from cloud services.

n8n supports credential management, error workflows (trigger a separate workflow on failure), and workflow versioning. You can run it in Docker, on a VM, or in Kubernetes for high-availability setups. The community edition is free and open-source.

API Tutorial

Building your own webhook handler

When no-code platforms do not fit your needs, a custom webhook handler gives you complete control over the PDF generation flow.

Python webhook handler example

The following Python example uses Flask to receive a webhook, extract the URL from the payload, call the Pretty PDF API, and store the resulting PDF. This is a complete, production-ready starting point that you can extend with authentication, queuing, and error handling.

import os
import hashlib
import requests
from flask import Flask, request, jsonify

app = Flask(__name__)

API_KEY = os.environ["PRETTYPDF_API_KEY"]
API_URL = "https://api.prettypdfprinter.com/v1/generate/url"
PDF_DIR = "/var/pdfs"

# Track processed events for idempotency
processed_events = set()

@app.route("/webhook", methods=["POST"])
def handle_webhook():
    payload = request.get_json()

    # Deduplicate using event ID
    event_id = payload.get("event_id", "")
    if event_id in processed_events:
        return jsonify({"status": "duplicate"}), 200

    # Extract the URL to convert
    url = payload.get("url")
    if not url:
        return jsonify({"error": "No URL provided"}), 400

    # Call Pretty PDF API
    response = requests.post(
        API_URL,
        headers={"X-API-Key": API_KEY},
        json={
            "url": url,
            "template": "clean",
            "page_size": "A4"
        }
    )

    if response.status_code != 200:
        # Return non-200 so the webhook provider retries
        return jsonify({"error": "PDF generation failed"}), 502

    # Store the PDF
    filename = hashlib.sha256(url.encode()).hexdigest()[:16] + ".pdf"
    filepath = os.path.join(PDF_DIR, filename)
    with open(filepath, "wb") as f:
        f.write(response.content)

    # Mark event as processed
    processed_events.add(event_id)

    return jsonify({"status": "ok", "file": filename}), 200

This handler implements idempotency (skipping duplicate events), error propagation (returning non-200 so the webhook provider retries), and file storage. In production, replace the in-memory processed_events set with a database or Redis cache, and add webhook signature verification for your specific provider.

API Tutorial

Best practices

Follow these guidelines to build webhook-driven PDF workflows that are reliable, secure, and auditable.

Verify webhook signatures

Most webhook providers sign their payloads with a shared secret. Verify the signature on every incoming request to ensure the webhook is genuine and has not been tampered with. Never process unsigned or unverified webhooks in production — an open webhook endpoint without signature verification is an attack vector.

Implement idempotency

Webhook providers may deliver the same event multiple times due to retries or network issues. Track processed event IDs in a database or cache and skip duplicates. This prevents generating the same PDF twice, which wastes API quota and creates confusion in your output storage.

Handle async processing

For high-volume workflows, do not call the Pretty PDF API synchronously inside your webhook handler. Instead, accept the webhook, enqueue the PDF generation job (using Redis, RabbitMQ, SQS, or any job queue), and return a 200 response immediately. A background worker picks up the job and calls the API. This pattern prevents webhook timeouts and lets you control concurrency.

Set up failure alerts

Monitor your webhook handler for failures. Set up alerts (email, Slack, PagerDuty) when PDF generation fails repeatedly. Track the failure rate over time. Most webhook providers also offer delivery logs and failure notifications on their end — enable those as a secondary monitoring layer.

Log every generation

Maintain an audit trail of every PDF generated through your webhook pipeline. Log the event ID, source URL, timestamp, PDF file location, and any errors. This log is invaluable for debugging, compliance reporting, and understanding your PDF generation patterns over time.

Frequently asked questions about webhook integration

Currently, the API is request-based — you call it to generate a PDF. Webhook integration means using external webhook providers (Zapier, Make, n8n, or a custom handler) to trigger API calls when an event occurs. Outbound webhooks for PDF completion notifications are on the roadmap.
Zapier's free tier supports basic Zaps. However, the Pretty PDF API call uses Zapier's Webhooks action, which is available on paid plans. Check Zapier's current pricing for details on webhook support and included task volume.
Implement idempotency in your webhook handler. Track processed event IDs in a database or cache and skip duplicates. Most webhook providers include a unique event ID in the payload that you can use as a deduplication key.
Your webhook handler should implement retry logic. Return a non-200 status to the webhook provider so it retries the delivery. Log failures for investigation. Most providers retry failed webhooks 3 to 5 times with exponential backoff.

Start building automated PDF workflows

Connect Pretty PDF to your existing tools with webhooks. One trigger, one API call, one styled PDF — fully automated.