printpdf
printpdf copied to clipboard
using with wasm-pack shared reference problem
Hi! I am new to Rust. I want to show wasm generated pdf with live changes in browser.
How can I solve this shared reference problem? Is there a trait implementaion missing? How can I clone
or take ownership
of the doc? thank you.
Purpose:
to convert pdf to bytes array and sent to js side.
Code
use printpdf::*;
use serde::{Deserialize, Serialize};
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn create() -> JsValue {
let (doc, page1, layer1) =
PdfDocument::new("PDF_Document_title", Mm(247.0), Mm(210.0), "Layer 1");
let bytes: Vec<u8> = doc.save_to_bytes().unwrap();
serde_wasm_bindgen::to_value(&bytes).unwrap()
}
Build Command
wasm-pack build --target bundler
Error
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
Compiling printpdf v0.5.3
error[E0507]: cannot move out of `m.modification_date` which is behind a shared reference
--> /home/ulvi/.cargo/registry/src/github.com-1ecc6299db9ec823/printpdf-0.5.3/src/document_info.rs:77:56
|
77 | let info_mod_date = to_pdf_time_stamp_metadata(m.modification_date);
| ^^^^^^^^^^^^^^^^^^^ move occurs because `m.modification_date` has type `js_sys_date::OffsetDateTime`, which does not implement the `Copy` trait
error[E0507]: cannot move out of `m.creation_date` which is behind a shared reference
--> /home/ulvi/.cargo/registry/src/github.com-1ecc6299db9ec823/printpdf-0.5.3/src/document_info.rs:78:59
|
78 | let info_create_date = to_pdf_time_stamp_metadata(m.creation_date);
| ^^^^^^^^^^^^^^^ move occurs because `m.creation_date` has type `js_sys_date::OffsetDateTime`, which does not implement the `Copy` trait
error[E0507]: cannot move out of `m.creation_date` which is behind a shared reference
--> /home/ulvi/.cargo/registry/src/github.com-1ecc6299db9ec823/printpdf-0.5.3/src/xmp_metadata.rs:49:43
|
49 | let create_date = to_pdf_xmp_date(m.creation_date);
| ^^^^^^^^^^^^^^^ move occurs because `m.creation_date` has type `js_sys_date::OffsetDateTime`, which does not implement the `Copy` trait
error[E0507]: cannot move out of `m.modification_date` which is behind a shared reference
--> /home/ulvi/.cargo/registry/src/github.com-1ecc6299db9ec823/printpdf-0.5.3/src/xmp_metadata.rs:50:49
|
50 | let modification_date = to_pdf_xmp_date(m.modification_date);
| ^^^^^^^^^^^^^^^^^^^ move occurs because `m.modification_date` has type `js_sys_date::OffsetDateTime`, which does not implement the `Copy` trait
error[E0507]: cannot move out of `m.metadata_date` which is behind a shared reference
--> /home/ulvi/.cargo/registry/src/github.com-1ecc6299db9ec823/printpdf-0.5.3/src/xmp_metadata.rs:51:45
|
51 | let metadata_date = to_pdf_xmp_date(m.metadata_date);
| ^^^^^^^^^^^^^^^ move occurs because `m.metadata_date` has type `js_sys_date::OffsetDateTime`, which does not implement the `Copy` trait
For more information about this error, try `rustc --explain E0507`.
error: could not compile `printpdf` due to 5 previous errors
Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit status: 101
full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"
@ulvido you can't, it would need modifications to the user code in this example