command line pdf tools

picopdf#

A minimalist markdown to PDF converter with custom font support.

Usage#

Markdown to PDF#

Convert markdown to PDF using default fonts:

picopdf write -i input.md -o output.pdf

Use custom TrueType fonts:

picopdf write -i input.md -o output.pdf \
  --font-regular ~/fonts/regular.ttf \
  --font-bold ~/fonts/bold.ttf \
  --font-mono ~/fonts/mono.ttf

PDF Manipulation Tools#

Merge multiple PDFs:

picopdf tool merge file1.pdf file2.pdf file3.pdf -o merged.pdf

Split PDF into individual pages:

picopdf tool split -i input.pdf -o ./output_dir

Split PDF by page ranges:

picopdf tool split -i input.pdf -o ./output_dir -r "1-3,5,7-9"

Extract specific pages:

picopdf tool extract -i input.pdf -o output.pdf -p "1,3,5-7"

Delete specific pages:

picopdf tool delete -i input.pdf -o output.pdf -p "2,4,6-8"

Rotate all pages 90 degrees:

picopdf tool rotate -i input.pdf -o output.pdf

Rotate specific pages by custom angle:

picopdf tool rotate -i input.pdf -o output.pdf -a 180 -p "1,3,5"

Reorganize pages in custom order:

picopdf tool organize -i input.pdf -o output.pdf -n "3,1,2,4-6"

Architecture#

Four-stage markdown conversion pipeline:

  1. Markdown to AST/IR using pulldown-cmark
  2. AST to styled blocks with semantic styling
  3. Blocks to positioned lines and glyphs via layout engine
  4. Lines to PDF using pdf-writer with embedded fonts

Font Support#

Default fonts are built-in PDF Type1 fonts (Helvetica, Courier) requiring no embedding. Custom TrueType/OpenType fonts are fully embedded in the PDF with proper Unicode support.

Default PDFs are around pretty small (2-5KB), see this file as an example. Custom font PDFs include the full font files, typically 2-7MB depending on font complexity.

Supported Markdown#

  • Headings (H1-H4)
  • Paragraphs
  • Lists
  • Code blocks
  • Inline code

Example#

# Using 0xProto Nerd Font
picopdf write -i README.md -o README.pdf \
  --font-regular ~/.local/share/fonts/0xProto-Regular.ttf \
  --font-bold ~/.local/share/fonts/0xProto-Bold.ttf \
  --font-mono ~/.local/share/fonts/0xProtoMono-Regular.ttf