| Crates.io | pdf2image |
| lib.rs | pdf2image |
| version | 0.1.3 |
| created_at | 2024-05-07 09:58:37.725326+00 |
| updated_at | 2025-02-09 23:37:31.422801+00 |
| description | A simplified port of Python's pdf2image that wraps pdftoppm and pdftocairo to convert PDFs into images. |
| homepage | https://github.com/styrowolf/pdf2image |
| repository | https://github.com/styrowolf/pdf2image |
| max_upload_size | |
| id | 1232035 |
| size | 27,909 |
A simplified port of Python's pdf2image that wraps pdftoppmand pdftocairo (part of poppler) to convert PDFs to image::DynamicImages.
Add to your project: cargo add pdf2image
pdf2image requires poppler to be installed.
Windows users will have to build or download poppler for Windows. Python's pdf2image maintainer recommends @oschwartz10612 version. You will then have to add the bin/ folder to PATH or use the environment variable PDF2IMAGE_POPPLER_PATH.
using homebrew:
brew install poppler
Most distros ship with pdftoppm and pdftocairo. If they are not installed, refer to your package manager to install poppler-utils
conda)poppler: conda install -c conda-forge popplerpdf2image: pip install pdf2imageuse pdf2image::{PDF2ImageError, RenderOptionsBuilder, PDF};
fn main() -> Result<(), PDF2ImageError> {
let pdf = PDF::from_file("examples/pdfs/ropes.pdf").unwrap();
let pages = pdf.render(
pdf2image::Pages::Range(1..=8),
RenderOptionsBuilder::default().pdftocairo(true).build()?,
)?;
std::fs::create_dir("examples/out").unwrap();
for (i, page) in pages.iter().enumerate() {
page.save_with_format(format!("examples/out/{}.jpg", i + 1), image::ImageFormat::Jpeg)?;
}
Ok(())
}
.unwrap(), refactored unnecessary ones to return errors and added comments detailing why it is safe to call (Thank you @qarmin!).pdf2image includes code derived from Edouard Belval's pdf2image Python module, which is MIT licensed. Similarly, pdf2image is also licensed under the MIT License.