A lightweight Docker image (~100MB) that turns a project directory into a PDF document by rendering source code files in a clean, readable layout.
This project wraps the Rust-based code-to-pdf tool and is designed to be used as a simple, reproducible container for generating a code snapshot from any repository or folder.
.gitignore and .ignoreMount your project into the container at /code and let the tool generate the PDF in the current directory.
docker run --rm -v "$PWD":/code kelsoncm/code2pdf
Obtaining help:
docker run --rm -v "$PWD":/code kelsoncm/code2pdf --help
By default, the output PDF is created as output.pdf in the working directory used by the container process.
docker run --rm -v "$PWD":/code -v "$PWD":/output kelsoncm/code2pdf --out /output/project-code.pdf
This pattern is useful when you want the generated PDF to be saved outside the mounted project folder.
The container expects the source directory to be mounted at /code and uses that directory as the input walk path.
The default command is:
/usr/local/bin/c2pdf .
So the usual workflow is simply:
docker run --rm -v "$PWD":/code kelsoncm/code2pdf
The application does not require a dedicated config file, but it follows common project conventions while scanning input files.
The generator respects exclusion patterns declared in:
.gitignore.ignoreThis keeps generated PDFs focused on meaningful source files and avoids dumping generated artifacts, dependencies, or build outputs.
Custom fonts can be loaded with the --font option. You may pass either:
.ttf fileThis is useful when you want consistent branding or a specific monospaced style in the exported PDF.
The binary supports the following arguments and flags:
| Flag | Description | Default |
|---|---|---|
walk_path |
Positional path to the directory to process | Required; in this image, usually /code |
--out |
Output PDF path | output.pdf |
--exclude |
Comma-separated globs to ignore | pnpm-lock.yaml,Cargo.lock |
--name |
PDF document name | Project Code |
--include-path |
Include the file path at the top of each page | true |
--font |
System font name or path to a font file | Embedded default (Helvetica) |
--font-size |
Font size in points | 12.0 |
--margin-top |
Top margin in mm | 20.0 |
--margin-bottom |
Bottom margin in mm | 5.0 |
--margin-left |
Left margin in mm | 10.0 |
--margin-right |
Right margin in mm | 10.0 |
--page-text |
Custom text inserted at the top of each page | None |
--threads |
Number of Rayon worker threads | Automatic |
--image-quality |
Image compression quality from 0.0 to 1.0 |
0.85 |
--no-log |
Disable execution logs | false |
docker run --rm -v "$PWD":/code kelsoncm/code2pdf
docker run --rm -v "$PWD":/code kelsoncm/code2pdf --out /code/project-code.pdf
docker run --rm -v "$PWD":/code kelsoncm/code2pdf --exclude "target/**,.venv/**,node_modules/**"
docker run --rm -v "$PWD":/code -v "$PWD":/fonts kelsoncm/code2pdf --font /fonts/JetBrainsMono-Regular.ttf
This image uses a two-stage build:
c2pdf binaryThis keeps the final runtime image lighter and more predictable than building the binary inside the same layer.
This project is distributed under the terms of the repository license. See the LICENSE file for details.
Contributions are welcome. If you improve the Docker image, CLI behavior, or documentation, please open a pull request with a concise description of the change and its purpose.