Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
24 changes: 21 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,16 @@ jobs:
run: jake test

- name: Run tests (with rayon)
run: jake test-rayon --options "-p pdfitdown"
run: jake test-rayon

- name: Run tests (markup only)
run: jake test-markup

- name: Run tests (image only)
run: jake test-image

- name: Run tests (office only)
run: jake test-office

test-windows:
name: Test on windows-latest
Expand All @@ -101,7 +110,16 @@ jobs:
${{ runner.os }}-cargo-

- name: Run tests (no rayon)
run: cargo test
run: cargo test --release -p 'pdfitdown'

- name: Run tests (with rayon)
run: cargo test --features rayon -p "pdfitdown"
run: cargo test --release --features rayon -p 'pdfitdown'

- name: Run tests (markup only)
run: cargo test --no-default-features --features markup --release -p 'pdfitdown'

- name: Run tests (image only)
run: cargo test --no-default-features --features image --release -p 'pdfitdown'

- name: Run tests (office only)
run: cargo test --no-default-features --features office --release -p 'pdfitdown'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ tests/data/*.pdf
__pycache__/
target/
.wrangler/
.DS_Store
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ cd PdfItDown
cargo install --path crates/pdfitdown
```

> **Note:** The CLI requires the `cli` feature (enabled by default). To install the library only without CLI support, use `cargo install pdfitdown --no-default-features`.

You can now use the **command line tool**:

```
Expand Down Expand Up @@ -158,17 +160,36 @@ let converter = PdfItDownConverter::new();
converter.convert_directory("tests/data/testdir", true, true)?; // overwrite, recursive
```

#### Parallelization with `rayon`
#### Feature Flags

PdfItDown uses Cargo features to let you choose which converters to include:

| Feature | Description | Default |
|---------|-------------|---------|
| `cli` | Enables the command-line interface and `clap` dependency | ✅ |
| `image` | Enables image-to-PDF conversion (`png`, `jpg`, etc.) | ✅ |
| `office` | Enables Office document conversion (`docx`, `xlsx`, `pptx`) | ✅ |
| `markup` | Enables Markdown/HTML conversion and text-based formats | ✅ |
| `rayon` | Enables parallelized batch conversion | ❌ |

Enable the `rayon` feature for parallel conversion of multiple files:
**Examples:**

```toml
# Library only, no CLI
[dependencies]
pdfitdown = { version = "4.0", default-features = false, features = ["markup", "image"] }

# All converters + parallelization
[dependencies]
pdfitdown = { version = "4.0", features = ["rayon"] }
```

```bash
# Install CLI with all features
cargo install pdfitdown --features rayon

# Install library only (e.g. for WASM or embedded use)
cargo install pdfitdown --no-default-features --features markup
```

### Python Legacy
Expand Down
Binary file removed README.pdf
Binary file not shown.
38 changes: 27 additions & 11 deletions crates/pdfitdown/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,43 @@ description = "PdfItDown: Convert anything to PDF."
keywords = ["pdf", "conversion", "office", "images", "markup"]

[dependencies]
clap = { version = "4.6.1", features = ["derive"] }
flate2 = "1.1.9"
image = "0.25.10"
infer = { version = "0.19.0", default-features = false }
clap = { version = "4.6.1", features = ["derive"], optional = true }

flate2 = { version = "1.1.9", optional = true }
image = { version = "0.25.10", optional = true }

infer = { version = "0.19.0", default-features = false, optional = true }

office2pdf = { version = "0.6.0", features = ["wasm", "wasm-bindgen"], optional = true }

office2pdf = { version = "0.6.0", features = ["wasm", "wasm-bindgen"] }
rayon = { version = "1.12.0", optional = true }

regex = "1.12.4"

[target.'cfg(target_arch = "wasm32")'.dependencies]
markdown = "1.0.0"
printpdf = {version = "0.9.1", features = ["web-sys", "wasm-bindgen-futures", "html", ] }
web-sys = "0.3.103"
markdown = { version = "1.0.0", optional = true }
printpdf = { version = "0.9.1", features = ["web-sys", "wasm-bindgen-futures", "html"], optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
markdown2pdf = "1.5.0"
html-to-markdown-rs = "3.8.0"
markdown2pdf = { version = "1.5.0", optional = true }
html-to-markdown-rs = { version = "3.8.0", optional = true }

[features]
rayon = ["dep:rayon"]
default = ["cli", "image", "office", "markup"]

cli = ["dep:clap"]
image = ["dep:flate2", "dep:image", "dep:infer"]
office = ["dep:office2pdf", "dep:infer"]
rayon = ["dep:rayon"]

markup = ["dep:markdown", "dep:printpdf", "dep:markdown2pdf", "dep:html-to-markdown-rs"]

[[bin]]
name = "pdfitdown"
path = "src/main.rs"
required-features = ["cli"]

[dev-dependencies]
tempfile = "3.27.0"
zip = "2"
infer = { version = "0.19.0", default-features = false }
32 changes: 27 additions & 5 deletions crates/pdfitdown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ Or enable parallelization with the `rayon` feature:
pdfitdown = { version = "4.0", features = ["rayon"] }
```

### Feature Flags

| Feature | Description | Default |
|---------|-------------|---------|
| `cli` | Command-line interface (`clap`) | ✅ |
| `image` | Image-to-PDF conversion | ✅ |
| `office` | Office document conversion (`docx`, `xlsx`, `pptx`) | ✅ |
| `markup` | Markdown/HTML and text-based format conversion | ✅ |
| `rayon` | Parallelized batch conversion | ❌ |

```toml
# Library only — no CLI, only markup and image support
[dependencies]
pdfitdown = { version = "4.0", default-features = false, features = ["markup", "image"] }

# Minimal — markup only
[dependencies]
pdfitdown = { version = "4.0", default-features = false, features = ["markup"] }
```

## Usage

### Basic Conversion
Expand Down Expand Up @@ -112,12 +132,14 @@ pdfitdown -d tests/data/testdir --recursive

## API Overview

The crate exposes a unified `Converter` trait and a composite `PdfItDownConverter` that delegates to specialized converters:
The crate exposes a unified `Converter` trait and a composite `PdfItDownConverter` that delegates to specialized converters. Each converter is available only when its corresponding feature is enabled:

- **`ImageConverter`** — Converts image files to PDF via the `image` crate.
- **`OfficeConverter`** — Converts Word, Excel, and PowerPoint via `office2pdf`.
- **`MarkupConverter`** — Converts Markdown and HTML via `markdown2pdf`.
- **`TextConverter`** — Converts plain text and text-based formats via `markdown2pdf`.
| Converter | Feature | Description |
|-----------|---------|-------------|
| `ImageConverter` | `image` | Converts image files to PDF via the `image` crate. |
| `OfficeConverter` | `office` | Converts Word, Excel, and PowerPoint via `office2pdf`. |
| `MarkupConverter` | `markup` | Converts Markdown and HTML via `markdown2pdf`. |
| `TextConverter` | `markup` | Converts plain text and text-based formats via `markdown2pdf`. |

All converters implement:

Expand Down
Loading
Loading