Skip to content

Instantly share code, notes, and snippets.

@kadru
Last active March 7, 2026 15:20
Show Gist options
  • Select an option

  • Save kadru/62c2f6c1def7cf62465e62acb1911ff7 to your computer and use it in GitHub Desktop.

Select an option

Save kadru/62c2f6c1def7cf62465e62acb1911ff7 to your computer and use it in GitHub Desktop.
opencode tool for readpdfs
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