fschutt / printpdf

An easy-to-use library for writing PDF in Rust
https://docs.rs/printpdf/
MIT License
777 stars 95 forks source link

Cannot convert from BmpDecoder #114

Open tronta opened 2 years ago

tronta commented 2 years ago

I used to embed an image like this:

        let image_bytes = include_bytes!("../data/image.bmp");
        let mut image_file = Cursor::new(image_bytes.as_ref());
        let Bmp = image_crate::bmp::BmpDecoder::new(&mut image_file).unwrap();
        let logo = Image::try_from(Bmp).unwrap();

But with the new version I get the following error message when using the try_from:

the trait bound `printpdf::Image: std::convert::From<exporter::document::image_crate::bmp::BmpDecoder<&mut std::io::Cursor<&[u8]>>>` is not satisfied
the following implementations were found:
  <printpdf::Image as std::convert::From<printpdf::ImageXObject>>
required because of the requirements on the impl of `std::convert::Into<printpdf::Image>` for `exporter::document::image_crate::bmp::BmpDecoder<&mut std::io::Cursor<&[u8]>>`
required because of the requirements on the impl of `std::convert::TryFrom<exporter::document::image_crate::bmp::BmpDecoder<&mut std::io::Cursor<&[u8]>>>` for `printpdf::Image`rustcE0277
mod.rs(479, 5): required by `std::convert::TryFrom::try_from`

Anything special I need to do now?

bastibense commented 8 months ago

Same issue here. Apparently something is broken.

I looked at the examples (image example) and tried the way OP mentioned above.

Something is broken with the dependency on the image_crate dep. Any suggestions or workarounds?

bastibense commented 8 months ago

After doing some research I defined "embedded_images" as feature in my Cargo.toml.

Sadly I didn't stumble across this in the docs or examples. Only by actually looking at the printpdf sources.

[dependencies]
printpdf = { version = "0.6.0", features = [ "embedded_images" ] }

Maybe that helps.