repo2pdf is an innovative and versatile tool designed to seamlessly transform GitHub repositories into well-formatted, visually engaging, and easy-to-navigate PDF files. By automating the process of cloning repositories and parsing code files, repo2pdf serves a variety of use-cases including teaching, code reviews, offline referencing, archiving, AI training, and document embedding. The tool's flexibility expands the horizons of interacting with codebases by bridging the gap between the dynamic world of coding and the static, universally accessible format of PDFs, catering to a multitude of user needs and creative applications.
- Example PDF
- Installation and Usage
- Configuration
- Troubleshooting / FAQ
- Contributing to repo2pdf
- Project Structure
- License
We have transformed the FreeCodeCamp repository from 42,998 files into a 186,453-page PDF in under 2 minutes. This conversion is purely for example and stress testing purposes. All content belongs to the original authors at FreeCodeCamp. |
repo2pdf can be installed by either cloning the repository from GitHub or directly using NPX. The steps and prompts vary based on the chosen method.
This method downloads and installs the latest version of repo2pdf from the NPM registry.
- Install repo2pdf using NPX:
npx repo2pdf
- The script will start running. Follow the prompt and provide the necessary information:
- GitHub repository URL
- Output file name
- Decision on whether to keep the cloned repository (Y/N)
This method involves manually cloning the repo2pdf repository and setting it up on your local machine.
- Clone the repository:
git clone https://github.com/BankkRoll/repo2pdf
- Navigate to the repo2pdf directory:
cd repo2pdf
- Install the dependencies:
npm install
- Build the script:
npm run build
- Run the script:
npm start
- The script will start running. Follow the prompt and provide the necessary information:
- Decision on whether to clone a repository or use a local repository
- If using a local repository, provide the path
- If cloning a repository, provide the URL
- Decision on whether to include line numbers in the PDF
- Decision on whether to include highlighting in the PDF
- Decision on whether to remove comments from the code
- Decision on whether to remove empty lines from the code
- Decision on whether to have one large file or one PDF per file in your repo
- If choosing one large file, you have two additional options:
- Whether to add page numbers
- Whether to add a table of contents (this feature is coming in the future)
- If choosing one large file, you have two additional options:
- Name of the output PDF file or output directory
- Decision on whether to keep the cloned repository after generating the PDF
- Decision on whether to clone a repository or use a local repository
Please note that you need to have Node.js installed on your system in order to run repo2pdf.
repo2pdf automatically ignores certain file types and directories (e.g., .png
, .git
).
To customize the files and directories to ignore, you can add a repo2pdf.ignore
file to the root of your repository.
Please note that if you use a local repository, the repo2pdf.ignore
file must be in the root of the repository directory. And you might need to add more directories to the ignore list, as the script not automatically ignores different build files and directories.
{
"ignoredFiles": ["tsconfig.json"],
"ignoredExtensions": [".md"]
}
Q: I'm getting an error "Failed to install [package-name]". What should I do?
A: Make sure you have Node.js and npm installed on your system. Try running the following command to install the required package manually:npm install [package-name]
Q: How can I customize the styling of the generated PDF?
A: You can modify the code in `clone.ts` or `syntax.ts` to change the font, font size, colors, and other styling options for the PDF document.// Example: Changing font size in syntax.ts
doc.fontSize(12);
Q: What types of files are supported for conversion to PDF?
A: Currently, repo2pdf supports all text-based files for conversion to PDF. Binary files like images or compiled binaries are ignored.Q: How can I modify the ignored files list?
A: You can add a `repo2pdf.ignore` file to the root of your repository to customize the list of ignored files. Here's an example of how to structure this file:{
"ignoredFiles": ["tsconfig.json"],
"ignoredExtensions": [".md"]
}
Q: How can I include line numbers in the generated PDF?
A: During the execution of the script, you'll be prompted with the question "Include line numbers?". Answering 'Y' will include line numbers in the generated PDF.Q: How can I keep the cloned repository after generating the PDF?
A: You'll be asked "Keep cloned repository?" during the script execution. Answer 'Y' to keep the cloned repository on your system after the PDF is generated.Q: How can I generate a PDF for a local repository?
A: When running the script, you'll be asked to either clone a repository or use a local one. Choose the latter and provide the local repository path.Your insights, skills, and valuable time can make a huge difference in the evolution of repo2pdf! We're always excited to see the community helping in shaping this tool to be even more efficient and feature-rich.
Encountered a hiccup? We're here to help! Please:
- Open an issue on GitHub detailing the bug.
- Describe the problem in depth. Share the steps to reproduce the issue and any error messages you received.
- If possible, provide information about your operating system and Node.js version.
Have a brilliant idea for a new feature or an improvement to an existing one? We're all ears! Please:
- Open an issue on GitHub to share your suggestions.
- Be as detailed as possible, explaining what you want to achieve and why it would be beneficial to the project.
If you're up for rolling up your sleeves to contribute code to fix a bug or implement a new feature, here's how you can get started:
- Fork the repository.
- Create a new branch for your changes.
- Make your changes in your branch.
- Submit a pull request from your branch to the main repo2pdf repository.
In your pull request, please provide a clear description of the changes you've made. We appreciate contributions that adhere to our coding conventions and are consistent with the existing codebase - it helps us maintain the quality of the project and makes the review process more efficient.
Here are some feature ideas and improvements that could be implemented in repo2pdf to enhance its functionality and user experience:
- Table of Contents Generation: Auto-generate sections based on directories and subsections based on files.
- Customizable Themes: Enable customizations for fonts, colors, and layout of the generated PDF.
- Selective File Inclusion: Add the feature to include specific files or directories from the repository.
- Parallel Processing: Leverage multi-threading or worker threads for faster conversion of large repositories.
- Interactive Progress Bar: Show a real-time progress bar in the terminal during the conversion process.
- Syntax Theme Customization: Support popular syntax highlighting themes like Monokai, Dracula, etc.
- Support for Private Repositories: Implement OAuth2 GitHub authentication for private repositories.
- Enhanced Error Handling: Provide clear error messages when a repository cannot be cloned.
- Conversion Options Presets: Define presets like 'minimalist': no line numbers, no highlighting, 'full-featured': line numbers, syntax highlighting.
- Support for Additional VCS: Extend support for other version control systems like GitLab, Bitbucket, and others.
- Support for Non-Git Repositories: Add support for other version control systems such as Mercurial or SVN.
- Client-Side Web Application: Develop a user-friendly web application for converting repositories and customizing settings.
- Text Compression: Use font subsetting and compression techniques to reduce the size of the generated PDF.
Feel free to contribute to the project by implementing any of these ideas or suggesting new ones!
We're ever grateful for the valuable contributions from our community. Meet the people who're helping shape repo2pdf:
Type | File/Folder | Description |
---|---|---|
π | src/ | The home of all source files. This is where the magic happens, transforming repositories into beautiful PDFs. |
π/π | src/clone.ts | This script is the workhorse of the project, taking care of cloning the repository and kick-starting the conversion to PDF. |
π/π | src/configHandler.ts | Like a conductor leading an orchestra, this script manages all configuration-related tasks and coordinates the interactions with the user. |
π/π | src/loadIgnoreConfig.ts | Think of this script as the gatekeeper. It loads the ignore configuration file and ensures that unneeded files and directories are left out of the conversion process. |
π/π | src/syntax.ts | The artist of the project. This script adds a splash of color to the PDF by implementing syntax highlighting and mapping highlight.js classes to specific colors. |
π/π | src/universalExcludes.ts | This script is the bouncer, maintaining a list of file and directory names and extensions that are always excluded from the conversion process. |
π | LICENSE.md | The rules of the road. This file outlines how others can use and share repo2pdf, ensuring everyone plays fair. |
π | package-lock.json | A snapshot of the exact versions of npm dependencies our project uses. It ensures that the environment is consistent every time you install. |
π | package.json | The ID of our project. It defines the project metadata, scripts, and dependencies and is essential for npm to understand how to handle the project. |
π | README.md | The project's handbook. It provides a comprehensive overview and detailed instructions on how to use repo2pdf. |
π | repo2pdf.ignore | The project's personal assistant. This file lists files and directories that should be excluded during the conversion, helping to tailor the output to your needs. |
π | tsconfig.json | The project's blueprint. This file holds the configuration for the TypeScript compiler, directing how the source code is transformed into the final JavaScript code. |
repo2pdf is open source software, licensed under the MIT License. See the LICENSE
file for more information.