blob: 9b956911fecb0fc4114f0d2a9034795e3c1299a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
use crate::pdfgen;
use wasm_bindgen::prelude::*;
use js_sys;
use yew::prelude::*;
struct Form {
}
impl Component for Form {
type Message = ();
type Properties = ();
fn create(_props: Self::Properties, _link: ComponentLink<Self>) -> Self {
Self { }
}
fn update(&mut self, _msg: Self::Message) -> ShouldRender {
false
}
fn change(&mut self, _props: Self::Properties) -> ShouldRender {
false
}
fn view(&self) -> Html {
let pdf_raw = /*include_bytes!("../demo.pdf"); // this works */pdfgen::genpdf(); // this doesn't work
let pdf = std::str::from_utf8(&pdf_raw).expect("should be able to convert to string");
let uri_component: String = js_sys::encode_uri_component(pdf).into();
let href = format!{"data:application/pdf;charset=utf-8,{}", uri_component };
html!{
<a href=href download="demo.pdf" >
{ "Download PDF" }
</a>
}
}
}
#[wasm_bindgen(start)]
pub fn run_app() {
App::<Form>::new().mount_to_body();
}
|