PdfItDown is designed to be flexible and highly customizable, while also providing a ready-to-use solution that you can employ in your code immediately without any modifications.
Installation
Add to your Cargo.toml:
Or enable parallelized batch conversion with the rayon feature:
Feature flags
Let’s explore three levels of usage:
Level 1: Use PdfItDown as-is
To use the conversion features of PdfItDown, import the PdfItDownConverter struct and the Converter trait:
Once you have a PdfItDownConverter instance, you can convert single or multiple files, as well as all files within a directory:
Each conversion operation returns the PDF bytes (Vec<u8>) or writes directly to a file.
Level 2: Customize
Once you are comfortable with the basics, you may want more control within your application. PdfItDown offers the perfect solution: implement your own Converter trait.
Instead of using the default PdfItDownConverter, which can convert almost any file format to PDF, you can provide your own logic by implementing the Converter trait, focusing on specific document types.
The Converter trait requires two methods:You can also use the provided default methods convert_to_file, convert_multiple_files, and convert_directory.
Here is an example of a custom converter:
Level 3: Deploy
After defining your own logic, you can easily integrate PdfItDown into any Rust-based web framework such as Axum, Actix-web, or Rocket.
To use PdfItDown in a web server, ensure you handle file uploads and pass the bytes or file paths to the converter.
Here’s how you can use PdfItDown in an Axum application:
With this, you have completed the third and final level of PdfItDown mastery!