Last active
March 7, 2026 15:20
-
-
Save kadru/62c2f6c1def7cf62465e62acb1911ff7 to your computer and use it in GitHub Desktop.
opencode tool for readpdfs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { tool } from "@opencode-ai/plugin" | |
| import { existsSync } from "fs" | |
| export default tool({ | |
| description: "Extract and read text content from PDF files", | |
| args: { | |
| filePath: tool.schema.string().describe("Path to the PDF file"), | |
| offset: tool.schema.number().optional().describe("Page number to start reading from"), | |
| limit: tool.schema.number().optional().describe("Maximum number of pages to read"), | |
| }, | |
| async execute(args) { | |
| if (!existsSync(args.filePath)) { | |
| throw new Error(`File not found: ${args.filePath}`) | |
| } | |
| const proc = Bun.spawn(["pdftotext", args.filePath, "-"]) | |
| const output = await new Response(proc.stdout).text() | |
| return output | |
| }, | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment