SuperAPI AI Directory

pdf-image-text-extractor

Design & creation

View repository

Updated 10-16 08:08

About this skill

PDF and Image Text Extraction

1. Introduction

PDF and Image Text Extractionis a local tool from the Doubao Duck Community that intelligently recognizes and extracts text content from images and PDF documents. Whether it is a photo taken with a phone, a scanned PDF, or a digital PDF, it can automatically detect the presence of text, extract all text, and preserve the original layout and formatting, ultimately outputting structured Markdown text.

This duck turns tedious character-by-character transcription into a single command—running entirely locally, with no internet connection, no uploads, and no external transmission; files are processed right at your fingertips.

Core Value: Say goodbye to manual transcription and extract text from documents with one click, saving 90% of transcription time.

Target Users: Students (extracting text from textbooks/papers), office workers (extracting contract/invoice information), content creators (extracting reference materials), developers (batch processing documents).


2. Features

Feature Description
📷 Image Text Recognition Supports common formats such as PNG, JPG, JPEG, GIF, WebP, and BMP, automatically detecting and extracting text from images
📄 PDF Text Extraction Supports both scanned and text-based PDFs, preserving paragraph structure and heading hierarchy
🎯 Intelligent Detection Automatically determines whether a document contains text, and clearly prompts when there is no text, avoiding waiting in vain
📝 Structured Output Outputs in Markdown format, with clear hierarchy for headings, body text, and paragraphs, ready for direct reading or further editing
🌐 Multilingual Support Supports recognition and extraction of text in multiple languages, including Chinese and English
🔒 Privacy Protection Runs entirely locally, with no internet connection and no uploads; files are used only in the current session and are not persistently stored

Highlights:

  • Image text extraction requires no additional dependencies and directly uses the built-in read_image tool
  • PDF text extraction uses the PyMuPDF engine to accurately recognize font sizes and bold formatting, automatically generating Markdown heading levels
  • Output results can be flexibly chosen: displayed directly, saved as .md files, or embedded into other documents
  • Purely local processing; the script does not initiate any network requests, requiring no API key and no registration

3. One-Click Installation

Dependency Installation

Dependency Description Installation Command
pymupdf>=1.23.0 Core engine for PDF text extraction python3 -m pip install pymupdf>=1.23.0

Note: The image text extraction feature directly uses AI's built-in read_image tool, requiring no additional dependencies to be installed.pymupdf It only needs to be installed when PDF text extraction is required.

Environment Requirements

  • Python 3.7+
  • Supported operating systems: macOS / Linux / Windows

4. Usage Guide

Image Text Extraction

Workflow:

  1. Upload Image — Upload an image file containing text to the conversation
  2. Automatic recognition — The agent uses the read_image tool to automatically recognize image content and extract all text (including titles, body text, annotations, watermarks, etc.)
  3. Determine text existence — If text is detected, proceed to the next step; if no text is detected, the agent will clearly state "The image does not contain extractable text"
  4. Formatted output — Preserve the original text structure and layout, and organize it into an easy-to-read format

Optional branches:

  • When the user only needs to view the text content: output the text directly without generating a file
  • When the user requests to save the result: generate a .md file
  • When the image text is blurry or difficult to recognize: explain the situation and provide the best recognition result

PDF text extraction

Workflow:

  1. Upload PDF file — Upload the PDF file to the conversation
  2. Run the extraction script:
python3 scripts/pdf_text_extractor.py <pdf_file_path>
  1. View the extraction result — The script returns a JSON-format result, including:

    • success: whether it succeeded
    • text: text content in Markdown format
    • page_count: total number of pages
    • error: error message (if any)
  2. Formatted output — The text returned by the script is in Markdown format and can be displayed directly or saved as a file

Script parameter description:

Parameter Description Required
<pdf_file_path> Local path of the PDF file Yes

Output format example:

{
  "success": true,
  "text": "## 第一章 引言\n\n这是正文内容...\n\n---\n\n## 第二章 方法\n\n...",
  "page_count": 10,
  "error": ""
}

Optional branches:

  • When the PDF contains scanned images: inform the user that the page is a scanned image and may require OCR processing
  • When extraction fails: check whether the file exists, whether the format is correct, and whether the PDF is encrypted

Common commands / instructions quick reference table

Scenario Command / Operation
Extract image text Upload an image and directly ask the agent to recognize it
Extract PDF text python3 scripts/pdf_text_extractor.py <路径>
View only without saving After extraction, simply output the text directly
Save as file After extraction, ask the agent to generate a .md file
Install dependencies python3 -m pip install pymupdf>=1.23.0

5. Use cases

Scenario Role Need How to use Expected benefits
🔬 Academic research Graduate student / scholar Extract text from scanned PDF papers for notes and citations Upload PDF → run extraction script → obtain Markdown source text No manual typing required, accuracy 95%+, directly copy into papers for citation
💼 Office document processing Administration / legal / finance Extract key textual information from image contracts, invoices, and scanned documents Upload image → agent recognition → extract text Say goodbye to typing word by word and improve document digitization efficiency
✍️ Content secondary creation Self-media / editor Extract text from PDF e-books as creative material Upload PDF → Extract all text → Save as .md for editing Quickly obtain the original text and focus on content creation rather than transcription
💻 Batch document processing Developers / Data analysts Batch process multiple PDF documents and extract structured data Write scripts to call in a loop pdf_text_extractor.py Automated processing that can be integrated into data processing pipelines

6. Project Architecture

Directory Structure

pdf-image-text-extractor/
├── SKILL.md                          # Skill 定义文件
├── README.md                         # 用户文档(中文)
└── scripts/
    └── pdf_text_extractor.py         # PDF 文字提取核心脚本

Tech Stack

Technology Purpose Version Requirement
Python Script runtime environment 3.7+
PyMuPDF (fitz) PDF parsing and text extraction engine >=1.23.0

Core Module Description

scripts/pdf_text_extractor.py — Core PDF text extraction script:

  • extract_text_from_pdf(pdf_path) — Main extraction function, opens the PDF file, parses text blocks page by page, automatically generates Markdown format (## and ### headings) based on font size (>16px is determined to be a heading) and bold attributes, and outputs structured text containing page separators
  • main() — CLI entry point, receives the PDF file path parameter, calls the extraction function, and outputs the JSON result

The script runs entirely locally, does not make any network requests, and requires no API key or external account.

Resource Index

Resource Path Description
Core script scripts/pdf_text_extractor.py PDF text extraction script
User documentation README.md Chinese usage instructions

7. FAQ

Installation

Q: What should I do if an error occurs when installing pymupdf? A: Make sure the Python version is >= 3.7. Some systems may require installing system-level dependencies first: on macOS you can try brew install mupdf, and on Linux you can try apt-get install libmupdf-dev。

Q: Is it mandatory to install pymupdf? A: If you only use the image text extraction feature, it is not required. pymupdf is only needed when PDF text extraction is required.

Usage

Q: How accurate is image text extraction? A: Text recognition results are affected by factors such as image clarity, font, and background. For clear images, accuracy can reach 95%+, while accuracy decreases for blurry images or those with complex backgrounds.

Q: What is the text format like after PDF extraction? A: The script automatically generates Markdown-format output. Large-font lines are automatically converted to ## headings, bold large fonts become ### headings, and different pages are separated by --- .

Q: Will my files be uploaded? A: No. The script runs completely locally, does not make any network requests, files will not be uploaded or sent externally, and no API key is required.

Q: Can it handle encrypted PDFs? A: Encrypted or password-protected PDF files are not supported. They need to be decrypted before extraction.

Q: Can the extracted text be saved? A: Yes. After extraction, ask the agent to generate a .md file to save it locally.

Troubleshooting

Q: What should I do if the PDF extraction result is empty? A: Possible reasons: 1) The PDF is a scanned image (image-based PDF) and requires an OCR tool; 2) The PDF itself does not contain a text layer. For scanned PDFs, it is recommended to preprocess them with an OCR tool first.

Q: Processing is slow because the file is too large? A: It is recommended to process files smaller than 50MB. Files that are too large can be split before extraction.

Q: It says "File does not exist"? A: Confirm that the PDF file path is correct and that the file has been uploaded to the working directory. You can use an absolute path to avoid path issues.

Q: No text was detected in the image? A: Possible reasons: 1) The image indeed contains no text; 2) The text in the image is too blurry or blends into the background. Try extracting again using a higher-resolution image.