Repository navigation
feat: add feature flags - #83
Merged
Merged
Conversation
AstraBert
commented
Jul 1, 2026
Owner
- chore: feature flagging
- feat: add feature flags
added 2 commits
July 1, 2026 17:33
📄 Knowledge review✏️ Suggested updates1 page suggestion needs review.
📝 PdfItdown Converter@@ -8,22 +8,58 @@
The `PdfItDownConverter` provides a single interface for converting files and directories to PDF. It supports both file paths and in-memory data, and routes each input to the appropriate specialized converter based on file format.
+## 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 | ❌ |
+
+Each converter is only available when its corresponding feature is enabled:
+
+- `ImageConverter` requires the `image` feature
+- `OfficeConverter` requires the `office` feature
+- `MarkupConverter` and `TextConverter` require the `markup` feature
+
+**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"] }
+
+# Minimal markup-only configuration
+[dependencies]
+pdfitdown = { version = "4.0", default-features = false, features = ["markup"] }
+```
+
## Supported Formats
-- **Images**: PNG, JPG, JPEG, AVIF, TIFF, WEBP
-- **Office Documents**: DOCX, XLSX, PPTX
-- **Markup**: Markdown, HTML
-- **Text/Code**: TXT, JSON, CSV, XML, and many code formats (Rust, Python, JavaScript, TypeScript, etc.)
+The following formats are supported when their corresponding features are enabled:
+
+- **Images** (`image` feature): PNG, JPG, JPEG, AVIF, TIFF, WEBP
+- **Office Documents** (`office` feature): DOCX, XLSX, PPTX
+- **Markup** (`markup` feature): Markdown, HTML
+- **Text/Code** (`markup` feature): TXT, JSON, CSV, XML, and many code formats (Rust, Python, JavaScript, TypeScript, etc.)
- **PDF**: Pass-through (no conversion)
## Core Architecture
-The converter is organized into specialized modules, each implementing the `Converter` trait:
-
-- `crates/pdfitdown/src/img/mod.rs` - image conversion using the `image` crate
-- `crates/pdfitdown/src/office/mod.rs` - office document conversion via `office2pdf`
-- `crates/pdfitdown/src/markup/mod.rs` - markup conversion using `markdown2pdf`
-- `crates/pdfitdown/src/text/mod.rs` - text and code file conversion
+The converter is organized into specialized modules, each implementing the `Converter` trait. Modules are conditionally compiled based on feature flags:
+
+- `crates/pdfitdown/src/img/mod.rs` - image conversion using the `image` crate (`image` feature)
+- `crates/pdfitdown/src/office/mod.rs` - office document conversion via `office2pdf` (`office` feature)
+- `crates/pdfitdown/src/markup/mod.rs` - markup conversion using `markdown2pdf` (`markup` feature)
+- `crates/pdfitdown/src/text/mod.rs` - text and code file conversion (`markup` feature)
- `crates/pdfitdown/src/types.rs` - type definitions including `ConversionInput` and the `Converter` trait
## Usage in Rust
@@ -81,7 +117,7 @@
)?;
```
-Can be parallelized with the `rayon` feature enabled.
+Parallelization is available when the `rayon` feature is enabled.
### `convert_directory`
@@ -170,7 +206,7 @@
## CLI Integration
-The PdfItDown CLI uses the `PdfItDownConverter` to provide commands for converting files and directories to PDF. You can specify input files, output files, and directories directly from the command line. The CLI supports both single and batch conversions, with optional overwrite control and recursive directory conversion.
+The PdfItDown CLI uses the `PdfItDownConverter` to provide commands for converting files and directories to PDF. The CLI requires the `cli` feature, which is enabled by default. You can specify input files, output files, and directories directly from the command line. The CLI supports both single and batch conversions, with optional overwrite control and recursive directory conversion.
[See the CLI implementation.](https://github.com/AstraBert/PdfItDown/blob/main/crates/pdfitdown/src/main.rs)
✅ Accepted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.