blob: 38cfa58c315cf38668500d3e3bd4eeb7eff3f779 (
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 raw = pdfgen::genpdf();
let data = base64::encode(&raw);
let uri_component: String = js_sys::encode_uri_component(&data).into();
let href = format!{"data:application/pdf;base64,{}", 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();
}
|