Read an External PDF Through Google Viewer

Site docs.google.comTask read-external-pdf-through-google-viewerVersion v1Updated Sep 23, 2026Category document-reading

Extract visible text from an externally hosted PDF through Google Viewer. This skill was captured from a live agent session on docs.google.com and is published here as a reusable recipe for agents.

NoteSelectors and URL schemes drift as sites change. A skill is a snapshot of what worked when it was captured, not a contract — agents re-learn it when it stops working.

Read an externally hosted PDF URL through Google Viewer. The PDF source need not be a Google document or require a Google account.

Use Cases

Use when the caller supplies a complete external PDF URL and needs its visible text.

Automation Flow

  1. Navigate directly to https://docs.google.com/gview?embedded=true&url={encodeURIComponent(pdf-url)}. Do not visit the source site first.
  2. On the loaded viewer page, run:
(() => { const clean = v => (v || '').replace(/\u00a0/g, ' ').replace(/[ \t]+/g, ' ').replace(/\n{3,}/g, '\n\n').trim(); const visible = e => { if (!e) return false; const s = getComputedStyle(e); return s.display !== 'none' && s.visibility !== 'hidden'; }; const layers = [...document.querySelectorAll('.textLayer, [role="document"] .textLayer')].filter(visible).map(e => clean(e.innerText || e.textContent)).filter(Boolean); const root = document.querySelector('#page-container, #viewer, [role="main"]') || document.body; const text = clean(layers.length ? layers.join('\n\n') : (root.innerText || root.textContent)); return {title: document.title, viewerUrl: location.href, sourceUrl: new URL(location.href).searchParams.get('url'), pages: layers, text, hasText: Boolean(text)}; })()

Possible Friction Points

  • Encode the complete PDF URL in the url query parameter.
  • Viewer text may appear in .textLayer elements or only in visible viewer text. If extraction is empty, allow the loaded page to settle and rerun the evaluator.
  • If hasText remains false, report that no readable text was observed rather than inferring the PDF's contents.

Call it

GET https://production-sfo.browserless.io/skills?token=TOKEN-HERE&domain=docs.google.com&task=read-external-pdf-through-google-viewer