Gmail PDF Automation with Google Apps Script
Auto-delivering market reports to decision-makers — no server required
Most businesses receive structurally similar PDFs every week — supplier quotes, market reports, logistics documents, insurance terms. Reading and processing these is almost entirely manual: open the attachment, extract key numbers, fill in a spreadsheet, forward a summary. The problem is not document volume. It is the unnecessary manual step between "document arrives" and "information gets used."
If your team already uses Google Workspace (Gmail, Google Drive, Google Sheets), a significant portion of this workflow can be automated without standing up any server or requesting an IT budget. The tool is Google Apps Script.
A Real Deployment
A Hong Kong shipping company received daily market rate reports from multiple channels — inconsistent formats, mixed languages — requiring staff to manually consolidate them before any market assessment could happen. Delays measured in hours were routine.
The redesigned flow: Google Apps Script monitors a designated Gmail inbox. When it detects an email with a PDF attachment, it extracts the file, passes it to Gemini's native PDF processing interface for content parsing and summary generation, writes the result to Google Drive as an audit record, and pushes it to the relevant business group via Telegram Bot. From email arrival to summary delivery: zero human intervention.
This is a production deployment, not a proof of concept.
What Google Apps Script Is
Google Apps Script is Google's built-in automation scripting platform for Workspace. It runs JavaScript syntax directly in Google's cloud environment — no software to install, no server to manage.
Practical advantages for SMEs:
- Included in your Workspace subscription — no additional licensing cost
- Native integration with Gmail, Drive, Sheets, and Docs — no third-party connectors needed
- Time-based triggers — run automatically every morning at 9am, for example
- External API calls — compatible with LLM provider APIs including Gemini, Claude, and OpenAI
Its limits are equally clear: a six-minute execution ceiling per run, making it unsuitable for large batch processing. For scenarios requiring per-minute execution or thousands of documents, a proper backend pipeline is the right tool.
Why This Combination Works
Gmail as the trigger point fits how most businesses already receive documents — suppliers and clients do not need to change anything. Gemini's native PDF support removes the traditional OCR conversion step, handling both scanned documents and complex layouts without a separate parsing stage. Telegram solves the last-mile delivery problem: reports no longer sit in an inbox waiting to be opened; they are pushed directly to the decision-maker's phone.
Three tools, each doing one thing. Integration cost is far lower than procuring an enterprise document management system.
The Basic Flow Architecture
The complete automation pipeline, running entirely within Google's ecosystem:
Gmail Inbox
↓ Trigger: detect emails with PDF attachments matching subject criteria
Attachment Extraction
↓ Save PDF to designated Google Drive folder
Google Drive
↓ Read PDF content (binary to Base64)
Apps Script → LLM API Call
↓ Send document content + prompt to Gemini / Claude
Structured Output
↓ Write summary to Google Sheets
↓ Push via Telegram Bot to business group
No external servers involved. All files remain in your Google Drive. API keys are stored encrypted via Apps Script's Properties Service and never appear in source code.
Three Application Scenarios
Scenario 1: Daily Market Report Summary
Suppliers or data services send industry report PDFs daily. Staff read and extract key points manually. After automation: the system detects the email, extracts the attachment, calls an LLM to generate a three-to-five point summary, and delivers it to a Telegram group or writes it to a Google Sheets log before 9am. Applicable to logistics, finance, insurance, and procurement teams.
Scenario 2: Supplier Quote Comparison
Procurement receives multiple quote PDFs and copies numbers to a spreadsheet for manual comparison. After automation: the system extracts PDFs from multiple emails, instructs the LLM to pull product name, unit price, lead time, and payment terms from each document, and writes all results into a single Google Sheet as a comparison table. Note: accuracy is significantly higher when PDF formats are consistent across suppliers. Mixed formats require a human review step.
Scenario 3: Contract Clause Change Detection
Partners periodically send updated service terms or contract attachments. Staff compare with the previous version paragraph by paragraph. After automation: the system sends the new PDF to an LLM with instructions to compare against the previous version (also stored in Drive) and output added, modified, and removed clauses in structured format for legal or management review.
Google Drive's Role in the Pipeline
The Apps Script–Drive integration is a core strength of this approach. PDFs extracted from Gmail are stored in a designated Drive folder before processing, ensuring there is always a backup and the file can be reprocessed if needed. Files are named with dates, creating a queryable historical record for audits and comparisons. Drive triggers can also replace Gmail triggers — when a new file lands in a folder (such as a manually uploaded scan), the analysis pipeline starts automatically. Drive's sharing permissions apply to the entire flow, including the AI-generated analysis outputs, without requiring a separate access control mechanism.
Fixed-Scope Delivery
The value of this type of automation project comes from clearly defined requirements and boundaries. No full-time engineer hire required. No ongoing maintenance contract. Delivered on a fixed-scope, fixed-fee basis, with full source code handover and complete ownership transferred to the client. For teams evaluating their first AI automation entry point, document workflows carry the lowest risk and most directly measurable return — no changes to core business systems, immediate reduction in manual processing time. For a full picture of how these projects run end to end, see the six stages from scoping to handover.
Real Limitations — Before You Decide
These are platform design boundaries, not workarounds:
- Six-minute execution limit: A single Apps Script run has a hard ceiling of six minutes. Long PDFs or slow LLM API responses can hit this limit. Workarounds include task splitting or batch execution, but these increase setup complexity.
- PDF text layer requirement: LLM APIs receive PDFs as Base64. If the PDF is a pure image scan with no text layer, some models can process it visually, but accuracy is lower and token consumption increases significantly.
- API costs scale with volume: LLM APIs are usage-billed. Processing tens of reports per day can reach several hundred HKD per month depending on document length and model choice. Estimate expected volume before deploying.
- Not suitable for real-time response: The minimum trigger interval is one minute. If your process requires second-level response times, this approach is not appropriate.
When to Upgrade to a Proper Pipeline
Apps Script suits teams that already have Google Workspace, handle up to a few dozen documents per day, have relatively fixed processes, and lack a dedicated engineer. Consider a proper backend when:
- Processing hundreds of documents daily
- Bi-directional integration with ERP or CRM systems is needed
- Fine-grained error handling and retry logic is required
- Compliance or audit logging requirements apply
- Source document formats are diverse and require custom pre-processing
A proper pipeline carries higher build cost and complexity, but in these scenarios its reliability and scalability are outside the range of what Apps Script can deliver. For the broader technical framework of document automation, see AI document processing automation: methods and costs. For a structured checklist before committing to any AI project, see five questions to answer before AI adoption.
Levi is an independent AI engineer based in Hong Kong, building production-grade LLM applications, RAG pipelines, and document intelligence systems for SMEs pursuing AI digitalization internationally.
WhatsApp Free Initial Consultation → More enterprise case studies →Or email: support@hksoka.com