pdf-rs / pdf_render

MIT License
104 stars 21 forks source link

Does not compile #2

Closed dcompoze closed 2 years ago

dcompoze commented 2 years ago

Hi, I'm trying to compile this project with cargo +nightly build --bin view --release but I get the following errors:

error[E0432]: unresolved import `pdf::font::ToUnicodeMap`
 --> render/src/fontentry.rs:4:42
  |
4 | use pdf::font::{Font as PdfFont, Widths, ToUnicodeMap};
  |                                          ^^^^^^^^^^^^ no `ToUnicodeMap` in `font`

error[E0432]: unresolved import `pdf::content::TextDrawAdjusted`
 --> render/src/renderstate.rs:7:5
  |
7 | use pdf::content::TextDrawAdjusted;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `TextDrawAdjusted` in `content`

error[E0599]: no method named `transpose` found for enum `Option<&pdf::object::Stream>` in the current scope
  --> render/src/fontentry.rs:29:52
   |
29 |         let mut to_unicode = pdf_font.to_unicode().transpose().unwrap();
   |                                                    ^^^^^^^^^ method not found in `Option<&pdf::object::Stream>`
   |
   = note: the method was found for
           - `Option<Result<T, E>>`

Which looks like there are some missing types in the pdf library, even though I'm using the same Cargo.lock from master.

s3bk commented 2 years ago

Not quite sure why. I updated the Cargo.lock and it appears to work?

s3bk commented 2 years ago

It is probably time to remove the Cargo.lock entirely. It only causes problems.

Ploppz commented 2 years ago

@s3bk You could try cargo update or cargo clean maybe that helps to reproduce the error? I think removing Cargo.lock would only serve to potentially get more of these problems

dcompoze commented 2 years ago

I ran cargo update, and I managed to compile it afterwards. Although the resulting view binary seems to not work:

$ ./target/release/view example.pdf

Error: Try { file: "/home/foo/.cargo/git/checkouts/pdf-3ef1c528a9b91eec/baa9235/pdf/src/file.rs", line: 277, column: 23, source: FromPrimitive { typ: "RcRef < Catalog >", field: "root", source: Try { file: "/home/foo/.cargo/git/checkouts/pdf-3ef1c528a9b91eec/baa9235/pdf/src/file.rs", line: 93, column: 25, source: NullRef { obj_nr: 1 } } } }
s3bk commented 2 years ago

It looks like the PDF has no catalog? Broken files are not really supported at the moment.

dcompoze commented 2 years ago

@s3bk I took the file from the pdf-rs/pdf/files/example.pdf is that file broken? I also tried a couple of other pdf files and all of them cause an error like the above.

s3bk commented 2 years ago

Hm. then something is really broken. I will try to fix it today.

s3bk commented 2 years ago

https://github.com/pdf-rs/pdf/commit/9e56f00f19329d581d5eb8645c83c6a355e38c43 should fix it.

dcompoze commented 2 years ago

Great, that seems to have fixed it (at least for simple pdf files). Thanks!