Tools to convert PDFs and images to clean, well-formatted Markdown using Google Gemini 2.5 Flash. Both PowerShell and Bash variants are provided, with consistent logging and configurable thresholds.
imgconversion/
convert_images_to_markdown.ps1
convert_images_to_markdown.sh
logs/
per-tool log output
pdfconversion/
convert_pdfs_to_markdown.ps1
convert_pdfs_to_markdown.sh
logs/
per-tool log output
common/
Write-Log.psm1
PowerShell logging modulelog.sh
Bash logging helper
- A Google Generative Language API key
- Set
GOOGLE_GENAI_API_KEY
in your shell before running scripts.
- Set
- For Bash scripts
curl
,jq
,base64
,find
- Linux/macOS (or WSL on Windows)
- For PowerShell scripts
- PowerShell 7+ recommended
- Required
GOOGLE_GENAI_API_KEY
: your API key
- Optional logging
LOG_LEVEL
:DEBUG
(default),INFO
,WARN
,ERROR
- Bash logs to per-tool
logs/*.log
viacommon/log.sh
- PowerShell logs to per-tool
logs/*.log
viacommon/Write-Log.psm1
- Bash logs to per-tool
- Optional size thresholds
- Images (Bash):
IMG_MD_MAX_INLINE_BYTES
orIMG_MD_MAX_INLINE_MB
(default 3 MB) - PDFs (Bash):
PDF_MD_MAX_INLINE_BYTES
orPDF_MD_MAX_INLINE_MB
(default 15 MB) - Images (PowerShell): 3 MB inline threshold
- PDFs (PowerShell): 15 MB inline threshold
- Images (Bash):
.png
, .jpg
, .jpeg
, .webp
, .heic
, .heif
Initialize environment (PowerShell):
$env:GOOGLE_GENAI_API_KEY = 'your_api_key_here'
Run image conversion:
pwsh ./imgconversion/convert_images_to_markdown.ps1 -Paths "C:\path\to\image-or-folder"
Run PDF conversion:
pwsh ./pdfconversion/convert_pdfs_to_markdown.ps1 -Paths "C:\path\to\pdf-or-folder"
Notes
- If
-Paths
points to a directory, the script recursively processes supported files. - A
.md
file is created next to each source file; existing.md
files are skipped. - Logs are written to
imgconversion/logs/*.log
andpdfconversion/logs/*.log
.
Initialize environment (bash/zsh):
export GOOGLE_GENAI_API_KEY=your_api_key_here
# Optional: logging and thresholds
export LOG_LEVEL=INFO
export IMG_MD_MAX_INLINE_MB=3 # images (default 3MB)
export PDF_MD_MAX_INLINE_MB=15 # PDFs (default 15MB)
Run image conversion:
bash ./imgconversion/convert_images_to_markdown.sh /path/to/image-or-folder
Run PDF conversion:
bash ./pdfconversion/convert_pdfs_to_markdown.sh /path/to/pdf-or-folder
Notes
- If arguments are directories, scripts recurse to find supported files.
- Inline vs. File API is chosen by size threshold; you can override via env vars above.
- Logs are written to per-tool
logs/*.log
and are echoed to the console with colors.
PowerShell
common/Write-Log.psm1
providesInitialize-Logging
andWrite-Log
with levelsINFO|WARN|ERROR|DEBUG
.- Each tool initializes logging at start and writes to its own
logs/*.log
.
Bash
common/log.sh
provides alog LEVEL "message"
function.- Set
LOG_FILE
automatically by each tool to its locallogs/*.log
; adjust if needed.
- API key errors: ensure
GOOGLE_GENAI_API_KEY
is exported/set in the current shell. - Rate limiting: scripts add a small delay between items; consider increasing if needed.
- Large files: the File API path is used automatically when size exceeds the inline threshold.