Skip to main content

Overview

repo2pdf is a command-line tool that converts GitHub repositories into formatted PDF documents. This page provides a complete reference for all available commands and options.

Command

repo2pdf
The main command launches an interactive CLI that guides you through the PDF generation process.

Alternative Execution Methods

NPX (Recommended)

npx repo2pdf
Runs the latest version without installation

Local Installation

npm install -g repo2pdf
repo2pdf
Install globally for repeated use

Interactive Prompts

When you run repo2pdf, you’ll be guided through an interactive configuration process:

Repository Source

localRepo
choice
required
Choose between using a local repository or cloning from GitHub.Choices:
  • No - Clone from a GitHub URL
  • Yes - Use a local repository path

Local Repository Path

localRepoPath
string
The full filesystem path to your local repository.When shown: Only appears if you select “Yes” for local repositoryValidation: Path must exist on your filesystemExample: /home/user/projects/my-repo

GitHub Repository URL

repoUrl
string
The GitHub repository URL to clone and convert.When shown: Only appears if you select “No” for local repositoryFormat: Must be a valid GitHub URL: https://github.com/username/repositoryExample: https://github.com/BankkRoll/repo2pdf

Features Selection

features
array
required
Multi-select checkbox for PDF generation features.Available options:
Adds line numbers to the left side of all code in the PDF. The line numbers are automatically padded to align properly based on the total number of lines.Use case: Code reviews, teaching, referencing specific lines
Applies syntax highlighting to code based on file extension. Uses highlight.js to detect and colorize code syntax.Supported languages: JavaScript, TypeScript, Python, Java, C++, and 180+ other languages
Adds page numbers at the bottom center of each page in the format “Page: X of Y”.Note: Only available when generating a single PDF (not with “One PDF per file”)
Strips all comments from code files before adding to the PDF. Uses the strip-comments library to remove:
  • Single-line comments (//, #, etc.)
  • Multi-line comments (/* */, """ """, etc.)
Use case: Focus on code logic, reduce PDF size
Removes blank lines from code files to create more compact output.Use case: Reduce PDF page count, maximize code density
Generates a separate PDF for each file in the repository instead of a single combined PDF.Output: Creates a folder with individual PDFs named after each source file

Output File Name

outputFileName
string
default:"output.pdf"
The name of the generated PDF file.When shown: Only when “One PDF per file” is NOT selectedDefault: output.pdfExample: my-project-documentation.pdf

Output Folder Name

outputFolderName
string
default:"./output"
The folder where individual PDF files will be saved.When shown: Only when “One PDF per file” IS selectedDefault: ./outputExample: ./project-pdfs

Keep Cloned Repository

keepRepo
choice
Whether to keep the cloned repository on your filesystem after PDF generation.When shown: Only when cloning from GitHub (not for local repositories)Choices:
  • No - Delete the cloned repository after PDF generation
  • Yes - Keep the repository in ./tempRepo directory
Default: No

Configuration File

repo2pdf.ignore

Create a repo2pdf.ignore file in the root of your repository to customize which files and directories are excluded from the PDF. File format: JSON Example:
{
  "ignoredFiles": ["tsconfig.json", "dist", "node_modules"],
  "ignoredExtensions": [".raw", ".log"]
}
ignoredFiles
array
Array of file names or directory names to exclude.Example: ["package-lock.json", "node_modules", "dist", ".env"]
ignoredExtensions
array
Array of file extensions to exclude (including the dot).Example: [".raw", ".log", ".tmp", ".cache"]

Default Exclusions

repo2pdf automatically excludes common files and directories: Default excluded directories:
  • .git
  • node_modules
  • .next
  • dist
  • build
Default excluded extensions:
  • Images: .png, .jpg, .jpeg, .gif, .svg, .ico
  • Archives: .zip, .tar, .gz
  • Binaries: .exe, .dll, .so, .dylib
  • Media: .mp4, .mp3, .wav

Requirements

node
version
required
Minimum version: Node.js 18.0.0 or higherCheck your version:
node --version
git
binary
Required for: Cloning repositories from GitHubNot required for: Local repositoriesCheck if installed:
git --version

Dependencies

repo2pdf uses the following core dependencies:
PackageVersionPurpose
pdfkit^0.13.0PDF generation
highlight.js^11.9.0Syntax highlighting
simple-git^3.18.0Git operations
inquirer^9.2.6Interactive CLI prompts
chalk^5.2.0Terminal styling
ora^6.3.1Loading spinners
prettier^3.0.3Code formatting
strip-comments^2.0.1Comment removal
isbinaryfile^5.0.0Binary file detection

Exit Codes

CodeDescription
0Success
1General error (validation failure, file system error, etc.)

Examples

Basic Usage

npx repo2pdf
Then follow the prompts:
  1. Select “No” for local repository
  2. Enter: https://github.com/username/repo
  3. Select desired features (e.g., “Add line numbers”, “Add highlighting”)
  4. Enter output filename: my-project.pdf
  5. Select “No” to remove cloned repository

Local Repository

npx repo2pdf
  1. Select “Yes” for local repository
  2. Enter path: /home/user/projects/my-app
  3. Select features
  4. Enter output filename: local-project.pdf

Multiple PDFs

npx repo2pdf
  1. Select repository source
  2. Select “One PDF per file” in features
  3. Enter output folder: ./pdfs
  4. Each file will be saved as a separate PDF in the ./pdfs directory