Convert code repositories and directories to beautifully formatted PDFs with syntax highlighting.
- Syntax Highlighting - Automatic syntax highlighting for 20+ programming languages
- Directory Tree - Interactive table of contents with clickable file links
- Smart Filtering - Respects
.gitignorefiles (including nested ones) and skips binary files automatically - PDF Pagination - Automatically splits large repositories into multiple PDFs for reliable export
- GitHub Support - Clone and convert GitHub repositories directly
- Configurable - Customize output path, file size limits, and pagination settings
# Clone the repository
git clone https://github.com/ouuyu/code-to-pdf.git
cd code-to-pdf
# Install dependencies
pnpm install
# or
npm install
# Install Puppeteer Chrome (if not already installed)
npx puppeteer browsers install chrome# Convert current directory
node generate-pdf.cjs .
# Convert a specific directory
node generate-pdf.cjs ./src
# Convert with custom output name
node generate-pdf.cjs ./src -o my-code.pdf# Using owner/repo format
node generate-pdf.cjs facebook/react
# Using full URL
node generate-pdf.cjs https://github.com/facebook/react
# With custom file size limit (200KB)
node generate-pdf.cjs facebook/react --max-size 200
# With pagination (100 files per PDF)
node generate-pdf.cjs facebook/react --files-per-pdf 100Usage:
node generate-pdf.cjs [options] [input]
Arguments:
input Path to local directory or GitHub repository
Options:
-i, --input <path> Input path (default: ./src)
-o, --output <path> Output PDF file path (auto-generated if not specified)
-s, --max-size <kb> Maximum file size in KB to include (default: 100)
-f, --files-per-pdf <n> Maximum files per PDF for pagination (default: 50)
-h, --help Show this help message
-v, --version Show version information
# Show help
node generate-pdf.cjs --help
# Show version
node generate-pdf.cjs --version
# Convert with all options
node generate-pdf.cjs -i ./my-project -o output.pdf -s 150 -f 100
# Short form options
node generate-pdf.cjs -i ./src -o docs.pdf
# Convert GitHub repo with size limit
node generate-pdf.cjs microsoft/vscode --max-size 200
# Large repository with pagination
node generate-pdf.cjs torvalds/linux --files-per-pdf 50- Scans the directory or clones the GitHub repository
- Filters files using
.gitignorerules (including nested.gitignorefiles) and skips binary files - Generates HTML documents with:
- Interactive directory tree
- Syntax-highlighted code for each file
- Converts HTML to PDF using Puppeteer
- Paginates large repositories into multiple PDFs for reliability
The tool automatically skips:
- Files and directories in
.gitignore(respects nested.gitignorefiles) - Binary files (images, executables, etc.)
- Files larger than the size limit (default: 100KB)
- Default system directories:
.git,node_modules,dist,.vscode .gitignorefiles themselves
For large repositories, the tool automatically splits output into multiple PDFs:
- Default: 50 files per PDF
- Customize with
--files-per-pdfoption - Output files named:
output-part1.pdf,output-part2.pdf, etc. - Each part includes the full directory tree for reference
JavaScript, TypeScript, Python, Java, C++, C, Go, Rust, PHP, Ruby, C#, CSS, SCSS, LESS, HTML, XML, Markdown, JSON, YAML, Bash, SQL, and more...
- Node.js 18.11.0 or higher (for native
parseArgssupport) - Chrome/Chromium (installed automatically by Puppeteer)
MIT