Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure to read PDF with image #198

Open
nadenf opened this issue Sep 29, 2023 · 1 comment
Open

Failure to read PDF with image #198

nadenf opened this issue Sep 29, 2023 · 1 comment

Comments

@nadenf
Copy link

nadenf commented Sep 29, 2023

Using this to extract data from images:

      for (i, o) in images.iter().enumerate() {
            let img = match **o {
                XObject::Image(ref im) => im,
                _ => continue
            };

            let data = img.image_data(&resolver)?;

            let mut rgb_img: RgbImage = ImageBuffer::new(img.width, img.height);
            rgb_img.copy_from_slice(data.as_bytes());

Fails with this error:

thread 'indexer_pdf::tests::test_indexing' panicked at 'source slice length (5250) does not match destination slice length (15750)', src/indexer/document/src/indexer_pdf.rs:127:21
stack backtrace:
   0: rust_begin_unwind
             at /rustc/903e279f468590fa3425f8aff7f3d61a5a873dbb/library/std/src/panicking.rs:593:5
   1: core::panicking::panic_fmt
             at /rustc/903e279f468590fa3425f8aff7f3d61a5a873dbb/library/core/src/panicking.rs:67:14
   2: core::slice::<impl [T]>::copy_from_slice::len_mismatch_fail
             at /rustc/903e279f468590fa3425f8aff7f3d61a5a873dbb/library/core/src/slice/mod.rs:3603:13
   3: core::slice::<impl [T]>::copy_from_slice
             at /rustc/903e279f468590fa3425f8aff7f3d61a5a873dbb/library/core/src/slice/mod.rs:3610:13

With this PDF: Sample1.pdf

@s3bk
Copy link
Contributor

s3bk commented Sep 29, 2023

Not all images are RGB images.
You have to take a look at color_space to find out what it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants