Closed lusajo143 closed 1 week ago
I got the same problems and handled to solve it by changing the code a little bit. Since the project has not been developed more then 2 years, it has some mismatches with the loadpdf library. I first try to upgrade it to 0.33 but it didn't work so I also used the 0.29 version and works with the following changes.
The first error occurs because it's trying to map f64 values using a function (Real) that expects f32. Simply convert the f64 values to f32 before passing them to the Real function.
let identity_matrix: Vec<f64> = vec![1.0, 0.0, 0.0, 1.0, 0.0, 0.0];
let bbox: lopdf::Object = Array(
identity_matrix
.into_iter()
.map(|val| Real(val as f32)) // Convert f64 to f32
.collect()
);
The second issue occurs because there is no such method anymore... To extract numeric values from lopdf::Object, you should handle existing variants, such as Real for floating-point numbers and Integer for integers. Here's a helper method:
fn extract_f64(obj: &lopdf::Object) -> Result<f64, Error> {
match obj {
lopdf::Object::Real(val) => Ok(*val as f64), // Handle Real variant
lopdf::Object::Integer(val) => Ok(*val as f64), // Handle Integer variant
_ => Err(Error::Other("Expected a numeric value.".to_owned())), // Handle non-numeric variants
}
}
And then you can revise the code as follow:
let rect = Some(Rectangle {
x1: extract_f64(&child_rect[0])?,
y1: extract_f64(&child_rect[1])?,
x2: extract_f64(&child_rect[2])?,
y2: extract_f64(&child_rect[3])?,
});
I just updated the repo and everything should work now. The problem was because of dependencies that where not on crates.io yet. And since then the git repo's changed a lot. Should be fixed now and should keep working.
Hi @ralpha , I have been trying to run your example after creating all required certs, unfortunately I'm getting this error.
I have tried to change lopdf version to 0.29.0, I'm getting the following errors.