Read text from a caller-provided Google Doc or Slides presentation. Both text paths return {title, text}. Optionally export a Google Doc as PDF when requested.
Use Cases
Use when the caller supplies a Google Doc or Slides URL or ID and needs readable text. Preserve the caller's authenticated browser profile where permissions are required.
Automation Flow
- Read the opaque ID from
/document/d/{document-id}/or/presentation/d/{presentation-id}/in the supplied URL. Never fabricate an ID. - For Google Slides, navigate directly to
https://docs.google.com/presentation/d/{presentation-id}/export/txt, then run:
(() => ({title: document.title, text: (document.body?.innerText || document.body?.textContent || '').trim()}))()- For a Google Doc, navigate directly to
https://docs.google.com/document/d/{document-id}/mobilebasic, then run:
(() => { const root = document.querySelector('#contents') || document.body; return {title: document.title, text: (root.innerText || root.textContent || '').trim()}; })()- When the caller requests an authenticated Google Doc PDF, from the loaded Doc page fetch
https://docs.google.com/document/d/{document-id}/export?format=pdfwith credentials and return validated PDF bytes:
(async () => { const m = location.pathname.match(/\/document\/d\/([^/]+)/); if (!m) return {ok:false,error:'Document ID not found'}; const r = await fetch(`/document/d/${encodeURIComponent(m[1])}/export?format=pdf`, {credentials:'include'}); const b = new Uint8Array(await r.arrayBuffer()); let s = ''; for (const x of b) s += String.fromCharCode(x); return {ok:r.ok,status:r.status,contentType:r.headers.get('content-type'),bytes:b.length,pdfBase64:btoa(s),isPdf:b.length >= 4 && s.slice(0,4) === '%PDF'}; })()Possible Friction Points
- Google Slides has a direct plain-text export at
/presentation/d/{presentation-id}/export/txt. - The
/mobilebasicsuffix is the direct readable representation for a Google Doc. - Preserve the caller's authenticated browser profile. An unauthenticated session may return sign-in, access-denied, or error content.
- For PDF retrieval, check
status,contentType, andisPdfbefore accepting the base64 result.