{"id":644,"date":"2026-03-21T22:52:58","date_gmt":"2026-03-21T14:52:58","guid":{"rendered":"https:\/\/pa.yingzhi8.cn\/index.php\/2026\/03\/21\/tools-pdf\/"},"modified":"2026-03-21T23:08:51","modified_gmt":"2026-03-21T15:08:51","slug":"tools-pdf","status":"publish","type":"post","link":"https:\/\/pa.yingzhi8.cn\/index.php\/2026\/03\/21\/tools-pdf\/","title":{"rendered":"PDF Tool"},"content":{"rendered":"<h1>PDF Tool<\/h1>\n<h1>PDF tool<\/h1>\n<p><code>pdf<\/code> analyzes one or more PDF documents and returns text.<\/p>\n<p>Quick behavior:<\/p>\n<ul>\n<li>Native provider mode for Anthropic and Google model providers.<\/li>\n<li>Extraction fallback mode for other providers (extract text first, then page images when needed).<\/li>\n<li>Supports single (<code>pdf<\/code>) or multi (<code>pdfs<\/code>) input, max 10 PDFs per call.<\/li>\n<\/ul>\n<h2>Availability<\/h2>\n<p>The tool is only registered when OpenClaw can resolve a PDF-capable model config for the agent:<\/p>\n<ol>\n<li><code>agents.defaults.pdfModel<\/code><\/li>\n<li>fallback to <code>agents.defaults.imageModel<\/code><\/li>\n<li>fallback to best effort provider defaults based on available auth<\/li>\n<\/ol>\n<p>If no usable model can be resolved, the <code>pdf<\/code> tool is not exposed.<\/p>\n<h2>Input reference<\/h2>\n<ul>\n<li><code>pdf<\/code> (<code>string<\/code>): one PDF path or URL<\/li>\n<li><code>pdfs<\/code> (<code>string[]<\/code>): multiple PDF paths or URLs, up to 10 total<\/li>\n<li><code>prompt<\/code> (<code>string<\/code>): analysis prompt, default <code>Analyze this PDF document.<\/code><\/li>\n<li><code>pages<\/code> (<code>string<\/code>): page filter like <code>1-5<\/code> or <code>1,3,7-9<\/code><\/li>\n<li><code>model<\/code> (<code>string<\/code>): optional model override (<code>provider\/model<\/code>)<\/li>\n<li><code>maxBytesMb<\/code> (<code>number<\/code>): per-PDF size cap in MB<\/li>\n<\/ul>\n<p>Input notes:<\/p>\n<ul>\n<li><code>pdf<\/code> and <code>pdfs<\/code> are merged and deduplicated before loading.<\/li>\n<li>If no PDF input is provided, the tool errors.<\/li>\n<li><code>pages<\/code> is parsed as 1-based page numbers, deduped, sorted, and clamped to the configured max pages.<\/li>\n<li><code>maxBytesMb<\/code> defaults to <code>agents.defaults.pdfMaxBytesMb<\/code> or <code>10<\/code>.<\/li>\n<\/ul>\n<h2>Supported PDF references<\/h2>\n<ul>\n<li>local file path (including <code>~<\/code> expansion)<\/li>\n<li><code>file:\/\/<\/code> URL<\/li>\n<li><code>http:\/\/<\/code> and <code>https:\/\/<\/code> URL<\/li>\n<\/ul>\n<p>Reference notes:<\/p>\n<ul>\n<li>Other URI schemes (for example <code>ftp:\/\/<\/code>) are rejected with <code>unsupported_pdf_reference<\/code>.<\/li>\n<li>In sandbox mode, remote <code>http(s)<\/code> URLs are rejected.<\/li>\n<li>With workspace-only file policy enabled, local file paths outside allowed roots are rejected.<\/li>\n<\/ul>\n<h2>Execution modes<\/h2>\n<h3>Native provider mode<\/h3>\n<p>Native mode is used for provider <code>anthropic<\/code> and <code>google<\/code>.<br \/>\nThe tool sends raw PDF bytes directly to provider APIs.<\/p>\n<p>Native mode limits:<\/p>\n<ul>\n<li><code>pages<\/code> is not supported. If set, the tool returns an error.<\/li>\n<\/ul>\n<h3>Extraction fallback mode<\/h3>\n<p>Fallback mode is used for non-native providers.<\/p>\n<p>Flow:<\/p>\n<ol>\n<li>Extract text from selected pages (up to <code>agents.defaults.pdfMaxPages<\/code>, default <code>20<\/code>).<\/li>\n<li>If extracted text length is below <code>200<\/code> chars, render selected pages to PNG images and include them.<\/li>\n<li>Send extracted content plus prompt to the selected model.<\/li>\n<\/ol>\n<p>Fallback details:<\/p>\n<ul>\n<li>Page image extraction uses a pixel budget of <code>4,000,000<\/code>.<\/li>\n<li>If the target model does not support image input and there is no extractable text, the tool errors.<\/li>\n<li>Extraction fallback requires <code>pdfjs-dist<\/code> (and <code>@napi-rs\/canvas<\/code> for image rendering).<\/li>\n<\/ul>\n<h2>Config<\/h2>\n<p>&#8220;`json5  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\n{<br \/>\n  agents: {<br \/>\n    defaults: {<br \/>\n      pdfModel: {<br \/>\n        primary: &#8220;anthropic\/claude-opus-4-6&#8221;,<br \/>\n        fallbacks: [&#8220;openai\/gpt-5-mini&#8221;],<br \/>\n      },<br \/>\n      pdfMaxBytesMb: 10,<br \/>\n      pdfMaxPages: 20,<br \/>\n    },<br \/>\n  },<br \/>\n}<\/p>\n<pre><code>\nSee [Configuration Reference](\/gateway\/configuration-reference) for full field details.\n\n## Output details\n\nThe tool returns text in `content[0].text` and structured metadata in `details`.\n\nCommon `details` fields:\n\n* `model`: resolved model ref (`provider\/model`)\n* `native`: `true` for native provider mode, `false` for fallback\n* `attempts`: fallback attempts that failed before success\n\nPath fields:\n\n* single PDF input: `details.pdf`\n* multiple PDF inputs: `details.pdfs[]` with `pdf` entries\n* sandbox path rewrite metadata (when applicable): `rewrittenFrom`\n\n## Error behavior\n\n* Missing PDF input: throws `pdf required: provide a path or URL to a PDF document`\n* Too many PDFs: returns structured error in `details.error = &quot;too_many_pdfs&quot;`\n* Unsupported reference scheme: returns `details.error = &quot;unsupported_pdf_reference&quot;`\n* Native mode with `pages`: throws clear `pages is not supported with native PDF providers` error\n\n## Examples\n\nSingle PDF:\n\n```json  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n{\n  &quot;pdf&quot;: &quot;\/tmp\/report.pdf&quot;,\n  &quot;prompt&quot;: &quot;Summarize this report in 5 bullets&quot;\n}\n<\/code><\/pre>\n<p>Multiple PDFs:<\/p>\n<p>&#8220;`json  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\n{<br \/>\n  &#8220;pdfs&#8221;: [&#8220;\/tmp\/q1.pdf&#8221;, &#8220;\/tmp\/q2.pdf&#8221;],<br \/>\n  &#8220;prompt&#8221;: &#8220;Compare risks and timeline changes across both documents&#8221;<br \/>\n}<\/p>\n<pre><code>\nPage-filtered fallback model:\n\n```json  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n{\n  &quot;pdf&quot;: &quot;https:\/\/example.com\/report.pdf&quot;,\n  &quot;pages&quot;: &quot;1-3,7&quot;,\n  &quot;model&quot;: &quot;openai\/gpt-5-mini&quot;,\n  &quot;prompt&quot;: &quot;Extract only customer-impacting incidents&quot;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>PDF Tool PDF tool pdf analyzes one or more PDF document [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-644","post","type-post","status-publish","format-standard","hentry","category-docs"],"_links":{"self":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts\/644","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/comments?post=644"}],"version-history":[{"count":2,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts\/644\/revisions"}],"predecessor-version":[{"id":699,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts\/644\/revisions\/699"}],"wp:attachment":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/media?parent=644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/categories?post=644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/tags?post=644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}