forked from saucer/saucer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
58 lines (48 loc) · 1.71 KB
/
main.cpp
File metadata and controls
58 lines (48 loc) · 1.71 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <saucer/smartview.hpp>
#include <saucer/modules/pdf.hpp>
#include <filesystem>
static constexpr const char *demo = R"html(
<!DOCTYPE html>
<html>
<body>
<h1>Welcome to saucer!</h1>
<p>This example demonstrates how to use the pdf module!</p>
<hr>
<p>The C++ code currently exposes the following functions:<p>
<ul>
<li>print(path: string)</li>
<li>print_with(opts?)</li>
</ul>
<p>You can use the Dev-Tools to call them!</p>
<p>See the "expose" example on how to interact with exposed functions</p>
</body>
</html>
)html";
namespace fs = std::filesystem;
coco::stray start(saucer::application *app)
{
auto window = saucer::window::create(app).value();
auto webview = saucer::smartview::create({.window = window});
using enum saucer::modules::pdf::layout;
auto pdf = saucer::modules::pdf{webview.value()};
webview->expose("print",
[&](const fs::path &path)
{
pdf.save({
.file = path,
// A4 Page
// This has to be inches, as not all backends support the metric system (this is insane)
.size = {.w = 8.27, .h = 11.69},
.orientation = portrait,
});
});
webview->expose("print_with", [&](const saucer::modules::pdf::settings &settings) { pdf.save(settings); });
webview->set_dev_tools(true);
webview->set_html(demo);
window->show();
co_await app->finish();
}
int main()
{
return saucer::application::create({.id = "example"})->run(start);
}