# PDF Converter
[](https://opensource.org/licenses/MIT)
[](https://opensource.org/licenses/Apache-2.0)
[](https://opensource.org/licenses/MIT)
A simple and efficient Rust library for converting images to PDF documents with support for multiple formats and commercial use.
## โจ Features
- ๐ผ๏ธ **Multi-format Support**: JPG, PNG, GIF, BMP, WebP
- ๐ **Single & Batch Conversion**: Convert individual files or entire folders
- ๐ **Smart A4 Fitting**: Automatic scaling with proper margins
- โ๏ธ **Configurable**: Custom DPI, margins, page size, document title
- ๐ **Performance Optimized**: Memory-efficient processing
- ๐ผ **Commercial Friendly**: MIT/Apache-2.0 dual license
- ๐ ๏ธ **Production Ready**: Comprehensive error handling and testing
## ๐ Quick Start
Add to your `Cargo.toml`:
```toml
[dependencies]
pdf-converter = "0.1.0"
```
### Basic Usage
```rust
use pdf_converter::PdfConverter;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let converter = PdfConverter::new();
// Convert a single image
converter.convert_image_to_pdf("image.jpg", "output.pdf")?;
// Convert entire folder to single PDF
converter.convert_folder_to_pdf("images/", "batch_output.pdf")?;
Ok(())
}
```
### Advanced Configuration
```rust
use pdf_converter::{PdfConverter, PdfConfig};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = PdfConfig {
dpi: 300.0,
margin_mm: 20.0,
title: Some("My Document".to_string()),
};
let converter = PdfConverter::with_config(config);
converter.convert_folder_to_pdf("images/", "high_quality.pdf")?;
Ok(())
}
```
## ๐ Performance
- **Single image**: ~1 second
- **Batch (4 images)**: ~6 seconds
- **Memory**: Optimized for large files
- **Quality**: 100-300 DPI support
## ๐งช Testing
Run the comprehensive test suite:
```bash
cargo run --bin comprehensive_test
```
Or quick validation:
```bash
cargo run --bin quick_test
```
## ๐ Project Structure
```
src/
โโโ lib.rs # Public API
โโโ converter.rs # Core conversion logic
โโโ error.rs # Error handling
examples/
โโโ basic_usage.rs # Simple example
โโโ batch_convert.rs # Batch processing
```
## ๐ผ Commercial Use
This project is **100% commercial-friendly**:
- โ
**Use in proprietary software**
- โ
**Sell products containing this code**
- โ
**No copyleft restrictions**
- โ
**Modify and redistribute**
- โ
**Patent protection** (Apache-2.0)
Perfect for:
- Commercial applications
- SaaS products
- Enterprise software
- Consulting projects
- Proprietary systems
## ๐ License
Dual licensed under your choice of:
- **MIT License** - Simple and permissive
- **Apache License 2.0** - Includes patent protection
See [LICENSE-MIT](LICENSE-MIT) and [LICENSE-APACHE](LICENSE-APACHE) for details.
## ๐ค Author
**topki**
๐ง Email: 259901434@qq.com
## ๐ค Contributing
Contributions are welcome! This project is designed for easy contribution with:
- Clear module separation
- Comprehensive error handling
- Extensive test coverage
- Good documentation
## ๐ Links
- [Documentation](https://docs.rs/pdf-converter)
- [Repository](https://github.com/topki/pdf-converter)
- [Issues](https://github.com/topki/pdf-converter/issues)
---
**Made with โค๏ธ by topki** โข **Commercial use permitted** โข **Production ready**