code2pdf

command module
v0.0.0-...-528da18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 13 Imported by: 0

README

code2pdf

Convert code directories to PDF documents. Analyzes directory structure, processes source code files and images with detailed logging and statistics, and generates a formatted PDF with syntax highlighting information and file metadata. Supports both local and global ignore patterns for flexible file filtering, and includes comprehensive image support.

Usage

go run .                              # Creates code.pdf with images included
go run . -o myproject.pdf            # Custom output file
go run . -font-size 8 -line-numbers  # Formatting options
go run . -exclude-images             # Skip all image files
go run . -include-images             # Explicitly include images (default)
go run . -version                    # Show version information

Options

  • -o string: Output PDF file name (default: "code.pdf")
  • -font-size float: Font size for code (default: 7.0)
  • -font string: Font name - Courier, Helvetica, Times (default: "Courier")
  • -line-numbers: Include line numbers in the PDF
  • -landscape: Use landscape orientation instead of portrait (default: true)
  • -include-images: Include image files in the PDF (default: true)
  • -exclude-images: Exclude image files from the PDF
  • -version: Show version and exit (format: YYYYMMDDHHMMSS)

File Filtering

Respects .gitignore, .code2pdf.ignore, and ~/.code2pdf.ignore files using standard gitignore syntax. The .git/ directory is always excluded by default.

Ignore File Priority: Patterns are checked in the following order:

  1. .gitignore (local project)
  2. .code2pdf.ignore (local project)
  3. ~/.code2pdf.ignore (global user settings)

Detailed Logging: Shows which files are ignored and which ignore rule caused the exclusion, including the source file (.gitignore, .code2pdf.ignore, ~/.code2pdf.ignore, or (default)).

Global Ignore Configuration

Create a ~/.code2pdf.ignore file in your home directory to set global ignore patterns that apply to all code2pdf operations:

# Example ~/.code2pdf.ignore
*.log
*.tmp
.DS_Store
Thumbs.db
node_modules/
.vscode/
.idea/

This is useful for ignoring common development artifacts across all your projects.

Build

make build    # Build executable
make run      # Run with go run
make test     # Run tests
make clean    # Clean build artifacts
make mod      # Tidy and vendor dependencies

Image Support

code2pdf now supports including image files in the generated PDF. Supported formats include:

  • JPEG (.jpg, .jpeg)
  • PNG (.png)
  • GIF (.gif)
  • BMP (.bmp)
  • TIFF (.tiff, .tif)

Images are automatically scaled to fit within the page while maintaining their aspect ratio. Each image gets its own page with proper headers and metadata.

Image Options:

  • By default, images are included in the PDF
  • Use -exclude-images to skip all image files
  • Use -include-images to explicitly include images (default behavior)

Image Processing:

  • Images are automatically scaled to fit within page margins while maintaining aspect ratio
  • Each image gets its own dedicated page with proper headers and metadata
  • Images are centered on the page for optimal presentation
  • Unsupported or corrupted images are gracefully handled with error messages

Architecture

Single-file Go program using github.com/jung-kurt/gofpdf for PDF generation. Supports 20+ file extensions with automatic language detection, binary file filtering, and image rendering.

Processing Statistics: Displays comprehensive stats including:

  • Total files included vs ignored
  • Image files included/excluded count
  • Binary files skipped count
  • Top 5 file types by count
  • Real-time logging of ignored files with specific rules
  • File size and modification time information

PDF Features:

  • Title page with project directory name
  • Table of contents with file types (text/image) and metadata
  • Page numbering with section information
  • Automatic page breaks for long files
  • Proper headers and footers throughout the document

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL