| name | pdf-text-extractor |
| description | Extract text content from PDF files and save as markdown files in the same folder. Use when user requests to extract, convert, or read text from PDF documents, create markdown from PDFs, or mentions extracting PDF content to text/markdown format. Trigger phrases include "extract text from PDF", "convert PDF to markdown", "read PDF and save as markdown", "extract PDF content", or when working with PDF files that need text extraction for documentation or analysis. |
PDF Text Extractor
Overview
Extracts text content from PDF files using iTextSharp library and saves the output as markdown files in the same directory as the source PDF. Handles multi-page PDFs, preserves text structure, and provides clear feedback on extraction results.
Quick Start
Basic usage:
cd .github\skills\pdf-text-extractor\scripts
.\Extract-PDF-Text.ps1 -PDFPath "C:\path\to\document.pdf"
Interactive mode (prompts for file selection):
.\Extract-PDF-Text.ps1
Output: Creates document.md in the same folder as document.pdf
Prerequisites
- PowerShell 5.1 or later (Windows PowerShell or PowerShell Core)
- Internet connection (for first-time iTextSharp NuGet package download)
- Read access to source PDF file
- Write access to output folder
Note: The script automatically downloads and installs the iTextSharp NuGet package if not already available.
Core Workflow
The script performs these steps automatically:
-
Validate Input
- If no PDF path provided, prompts user to select a file
- Validates file exists and has .pdf extension
- Checks read permissions
-
Setup iTextSharp Library
- Checks if iTextSharp is already loaded
- If not, downloads NuGet package to temp folder
- Loads iTextSharp assembly into PowerShell session
-
Extract Text Content
- Opens PDF document using iTextSharp
- Iterates through all pages sequentially
- Extracts text content from each page
- Preserves line breaks and paragraph structure
-
Generate Markdown Output
- Creates markdown file with same name as PDF
- Adds header with source PDF name and page count
- Adds page separators for multi-page documents
- Writes extracted text content
-
Save and Report
- Saves markdown file in same folder as source PDF
- Reports extraction statistics (pages processed, output file path)
- Opens output file location in Windows Explorer (optional)
Usage Examples
Example 1: Extract from specific PDF
.\Extract-PDF-Text.ps1 -PDFPath "C:\Documents\Report.pdf"
# Creates: C:\Documents\Report.md
Example 2: Extract from workspace PDF
# From workspace root
.\.github\skills\pdf-text-extractor\scripts\Extract-PDF-Text.ps1 -PDFPath ".\docs\manual.pdf"
# Creates: .\docs\manual.md
Example 3: Batch extract multiple PDFs
Get-ChildItem "C:\Documents\*.pdf" | ForEach-Object {
.\Extract-PDF-Text.ps1 -PDFPath $_.FullName
}
Example 4: Extract with error handling
try {
.\Extract-PDF-Text.ps1 -PDFPath ".\important.pdf"
Write-Host "Extraction successful"
} catch {
Write-Error "Failed to extract: $_"
}
Script Parameters
-PDFPath <string> # Path to PDF file (required or interactive)
# Can be absolute or relative path
# Must have .pdf extension
Output Format
The generated markdown file includes:
# Extracted from: [filename.pdf]
**Total Pages:** [count]
---
## Page 1
[Extracted text from page 1]
---
## Page 2
[Extracted text from page 2]
---
...
Error Handling
The script handles common scenarios:
- File not found: Clear error message with file path
- Invalid file type: Validates .pdf extension
- Access denied: Reports permission issues
- Empty PDF: Creates markdown file noting no text content
- Corrupted PDF: Reports iTextSharp parsing errors
- Network issues: Falls back if NuGet download fails
Integration with GitHub Copilot Workflows
When to Trigger This Skill
Use this skill when the user:
- Mentions "PDF" and "extract", "convert", or "read"
- Asks to "get text from PDF"
- Wants to "convert PDF to markdown"
- Needs to "analyze PDF content"
- Says "extract text from this document"
- References a specific PDF file and wants its content
Workflow Integration
Scenario 1: User provides PDF path
User: "Extract text from C:\docs\manual.pdf"
1. Run Extract-PDF-Text.ps1 with provided path
2. Report success and output location
3. Optionally read the generated markdown if user wants analysis
Scenario 2: User mentions PDF in workspace
User: "Convert the PDF in the docs folder to markdown"
1. Search workspace for PDF files
2. If multiple found, ask user to specify
3. Run extraction script
4. Confirm completion
Scenario 3: User wants to analyze PDF content
User: "What does the requirements.pdf say about authentication?"
1. Run extraction script to create markdown
2. Read the generated markdown file
3. Answer user's question based on extracted content
Scenario 4: Batch processing
User: "Extract all PDFs in the dataversesolutions folder"
1. Find all PDF files in specified folder
2. Run extraction script for each PDF
3. Report summary of processed files
Technical Details
iTextSharp Library
- Package: iTextSharp 5.5.13.3 (last open-source version)
- Source: NuGet.org
- License: AGPL (permissive for text extraction use cases)
- Alternative: Script can be modified to use other PDF libraries like PdfSharp or System.Drawing
Text Extraction Method
Uses iTextSharp's PdfTextExtractor.GetTextFromPage() with SimpleTextExtractionStrategy:
- Preserves reading order (left-to-right, top-to-bottom)
- Maintains line breaks
- Does not preserve formatting (bold, italic, fonts)
- Works with text-based PDFs (not scanned images)
Limitations
- Scanned PDFs: Cannot extract text from image-based PDFs (requires OCR)
- Formatting: Does not preserve fonts, colors, or styling
- Tables: May not preserve table structure perfectly
- Complex layouts: Multi-column layouts may have text order issues
- Encrypted PDFs: Cannot extract from password-protected PDFs
Troubleshooting
Common Issues
Issue: "Cannot download iTextSharp package"
- Solution: Check internet connection or manually download iTextSharp NuGet package
Issue: "No text extracted from PDF"
- Cause: PDF might be image-based (scanned document)
- Solution: Use OCR tool or convert to text-based PDF first
Issue: "Access denied" error
- Cause: Insufficient permissions or PDF is open in another program
- Solution: Close PDF viewer and ensure read/write permissions
Issue: "Text order is jumbled"
- Cause: Complex PDF layout with multiple columns or text boxes
- Solution: May need manual cleanup of generated markdown
Extension Ideas
The skill can be extended to support:
- OCR integration: Add Tesseract for scanned PDFs
- Metadata extraction: Extract PDF properties (author, title, dates)
- Selective extraction: Extract only specific pages or sections
- Format preservation: Better handling of tables, lists, and structure
- Batch processing: Built-in multi-file processing with progress bars
- Output formats: Support for plain text, JSON, or structured data formats
For Developers: Script Maintenance
The Extract-PDF-Text.ps1 script is designed to be:
- Self-contained: Downloads dependencies automatically
- Portable: Works on any Windows system with PowerShell
- Maintainable: Clear function separation and error handling
- Extensible: Easy to add new features or output formats
Key functions:
Get-iTextSharpLibrary: Downloads and loads iTextSharp
Extract-TextFromPDF: Core extraction logic
Save-MarkdownFile: Formats and saves output
See script comments for detailed implementation notes.