Skip to content

Conversation

@pc-style
Copy link
Owner

@pc-style pc-style commented Jan 27, 2026

🚀 Major Upgrade

This PR transforms pdf2md into a powerhouse PDF converter with 11 new features:

Performance

  • Parallel processing - Process multiple PDFs concurrently with -c N flag
  • Progress bar with ETA - Visual feedback for multi-file operations

New Modes

  • Vision mode (-m vision) - Send PDF pages as images to Gemini (better for scanned docs)
  • Streaming output (--stream) - Real-time AI response display
  • Watch mode (pdf2md watch <dir>) - Auto-convert new PDFs in a folder

Flexibility

  • stdin/stdout - Pipe support: cat file.pdf | pdf2md > out.md
  • Glob patterns - pdf2md "docs/**/*.pdf"
  • Custom prompts - --template invoice or --prompt "Extract tables"
  • Output formats - --format json|html|text|markdown

Efficiency

  • Resume/cache - --cache to skip already-processed files
  • Image extraction - --extract-images to save embedded images

New Commands

  • pdf2md watch <dir> - Watch and auto-convert
  • pdf2md templates - List prompt templates
  • pdf2md cache --clear - Clear file cache

Dependencies Added

  • p-limit - Concurrency control
  • cli-progress - Progress bars
  • chokidar - File watching
  • glob - Pattern matching

Summary by cubic

Major upgrade to pdf2md with parallel processing, vision mode, streaming, watch mode, templates, caching, and new output formats. Faster multi-file runs with better UX and shell-friendly piping.

  • New Features

    • Parallel converts with -c and a progress bar with ETA.
    • New modes: vision (-m vision), streaming (--stream), and watch (pdf2md watch <dir>).
    • Flexible I/O: stdin/stdout piping, glob patterns, and directory support.
    • Prompts: built-in templates (--template) and custom prompts (--prompt), plus pdf2md templates.
    • Output formats: markdown, json, html, text with --format.
    • Efficiency: hash-based caching (--cache, pdf2md cache --clear) and optional image extraction (--extract-images).
  • Dependencies

    • Added: p-limit, cli-progress, chokidar, glob, @types/cli-progress.

Written for commit 7b4a754. Summary will update on new commits.

…mode, and more

- Add parallel processing with configurable concurrency (p-limit)
- Add progress bar with ETA for multi-file operations (cli-progress)
- Add stdin/stdout pipe support for shell integration
- Add vision mode to send PDFs as images to Gemini
- Add streaming output for real-time AI responses
- Add watch mode to auto-convert new PDFs in a directory
- Add glob pattern support (e.g., docs/**/*.pdf)
- Add hash-based caching to skip already-processed files
- Add custom prompts and built-in templates (invoice, table, summary, code)
- Add output formats: markdown, json, html, text
- Add image extraction from PDFs
- Add templates and cache management commands

Amp-Thread-ID: https://ampcode.com/threads/T-019bff71-9c6b-71d1-b614-e480b6560ebf
Co-authored-by: Amp <amp@ampcode.com>
.option('--stdout', 'Output to stdout instead of file')
.option('--extract-images', 'Extract images from PDF')
.option('--list-templates', 'Show available prompt templates')
.action(async (input: string | undefined, opts: {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL: Convert command action handler is defined but not implemented, causing the command to fail to execute

const fileName = `image-${imageCount}.png`;
const outputPath = path.join(outputDir, fileName);

// Create a simple PNG from raw image data
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Image extraction saves raw data as .raw files instead of proper PNG files

const genAI = new GoogleGenerativeAI(apiKey);
const model = genAI.getGenerativeModel({ model: modelName });

// Load PDF and render pages as images
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Unclosed PDF document causes resource leaks

height: number;
}

export async function extractImages(filePath: string, outputDir: string): Promise<string[]> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Unclosed PDF document causes resource leaks

return savedPaths;
}

export async function hasImages(filePath: string): Promise<boolean> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Unclosed PDF document causes resource leaks

if (await processFile(fullPath, mode, apiKey)) {
successCount++;
}
async function readStdin(): Promise<Buffer> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: readStdin function has no error handling, leading to potential crashes

@kiloconnect
Copy link

kiloconnect bot commented Jan 27, 2026

Code Review Summary

Status: 6 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 5
SUGGESTION 0
Issue Details (click to expand)

CRITICAL

File Line Issue
src/commands/convert.ts 188 Convert command action handler is defined but not implemented, causing the command to fail to execute

WARNING

File Line Issue
src/utils/images.ts 37 Image extraction saves raw data as .raw files instead of proper PNG files
src/utils/gemini.ts 83 Unclosed PDF document in convertPdfWithVision function causes resource leaks
src/utils/images.ts 12 Unclosed PDF document in extractImages function causes resource leaks
src/utils/images.ts 53 Unclosed PDF document in hasImages function causes resource leaks
src/commands/convert.ts 165 readStdin function has no error handling, leading to potential crashes
Files Reviewed (7 files)
  • src/commands/convert.ts - 2 issues (1 CRITICAL, 1 WARNING)
  • src/utils/images.ts - 3 issues (3 WARNING)
  • src/utils/gemini.ts - 1 issue (1 WARNING)
  • src/commands/watch.ts - No issues
  • src/utils/cache.ts - No issues
  • src/utils/formats.ts - No issues
  • src/utils/templates.ts - No issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants