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
- Navigate directly to
https://docs.google.com/gview?embedded=true&url={encodeURIComponent(pdf-url)}. Do not visit the source site first. - 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
urlquery parameter. - Viewer text may appear in
.textLayerelements or only in visible viewer text. If extraction is empty, allow the loaded page to settle and rerun the evaluator. - If
hasTextremains false, report that no readable text was observed rather than inferring the PDF's contents.