Skip to main content

Working with Documents and PDFs

Create and extend Word documents and Google Docs, export to PDF, read long PDFs, and fill PDF forms

Alongside spreadsheets, the other half of file work is documents: reading long ones, producing new ones, and turning them into something you can send. Agents can do all three, in Google Docs, in Microsoft Word on Microsoft 365, and with PDFs.


Reading documents

Give an agent a link to a Word document, a Google Doc, a PDF, or a PowerPoint deck and it can read the contents.

Long documents are read page by page rather than truncated. A long PDF comes back as an opening window of pages together with the document's real page count and instructions for asking for more, so the agent can work its way to the section it needs instead of grinding through 300 pages to find one clause. It can request a specific page window — a single page or an inclusive range — and read a page as an image when the page is a scan, a diagram, or a form that only makes sense visually.

This is what makes document-heavy work practical: an agent extracting the termination clause from a contract, checking an invoice against a purchase order, or pulling figures out of a submitted report is reading the relevant pages, not guessing from the first few.

Choosing pages with the URL

The page window is requested in the URL itself, by adding a #page= clause to the PDF's link — the same idea as the tab and range clauses on a spreadsheet URL.

Clause

What it does

#page=12

Read page 12.

#page=12-15

Read pages 12 to 15, inclusive.

Pages are numbered from 1, as printed in a PDF reader. The clause is a PDF idea — it has no effect on a Word document or a Google Doc, which are read as a whole.

A short PDF arrives whole. Up to about fifty pages, the agent simply gets the document. Past that, it gets the first few pages plus a note saying how many pages the document really has and how to ask for the rest — which is why a long contract does not have to be read from the front.

Adding #page= to a short PDF is still worth doing when you know where the answer lives. It narrows what the agent reads to those pages, which keeps a step focused and cheap.

A single view returns at most about fifty pages. Ask for more and it returns the first part of what you asked for and says it trimmed — so read a long stretch in a few passes rather than one.

Two other cases behave differently from each other in a way worth knowing:

  • A range that runs off the end of the document is trimmed to the last real page, and the reply says so.

  • A page number that is entirely outside the document, or a clause that isn't a valid page number at all — #page=0, #page=abc, or a backwards range like #page=15-12 — is refused with the document's real page count, rather than quietly falling back to the first pages. The agent is told what the valid range is and can ask again.

This is stricter than the equivalent clause on a spreadsheet, which forgives a backwards range. For a document, a wrong page number usually means a wrong assumption about the document, and silently reading page 1 instead would hide it.

Creating documents

Agents can create documents from scratch:

  • add_google_doc creates a new Google Doc, optionally with initial content.

  • add_word_document creates a new Word document on Microsoft 365, optionally with initial content.

Content is supplied as Markdown and converted to a properly formatted document, so headings, lists, tables, bold and links all come out as real document formatting rather than literal asterisks.

An agent can also append to an existing Google Doc (append_to_doc), which is how running logs, appended case notes, and accumulating summaries are built up across a workflow.

Have the agent open the destination folder before creating a file, so the new document lands where you expect rather than in a default location.

Producing a PDF

Both document types can be exported to PDF — export_google_doc_to_pdf and export_word_doc_to_pdf. The export produces a new file and leaves the source document untouched, which is why it stays available even for documents a step is only allowed to read.

This is the normal last step of a document-producing workflow: build the document from a template, have it reviewed, export the PDF, and send that.

Filling PDF forms

When a PDF has form fields, an agent can fill them in. It opens the PDF, sees the actual field names from the form, supplies values, and gets back a new, filled PDF — the blank form is not modified.

That matters for the common case where the blank form is a controlled document: a claim form, a government filing, an onboarding pack. The template stays pristine and each completed copy is a new file.


Generating documents from templates

For formatted output that has to look a particular way every time — offer letters, purchase-order confirmations, exception notices — do not have an agent write the document from scratch. Use a template: a Word document or Google Doc with placeholders that the workflow fills with live data. The template owns layout and formatting; the workflow supplies the values.

This is covered in full in Generate Documents from Templates.


Protecting source documents

As with spreadsheets, a work item column that holds a document can be marked Read only, and the platform then does not offer agents the tools that would modify that file — appending to it, for instance. Reading it, and creating new files from it such as a PDF export, remain available.

Use this for anything the workflow reads but must not alter: the signed original, the controlled template, the customer's submission. See The File and Image Property Types.

Did this answer your question?