initial test commit

This commit is contained in:
Ondrej Vlach 2023-11-27 20:38:32 +01:00
commit b6cc3d4631
9 changed files with 2411 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
target/

2134
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

16
Cargo.toml Normal file
View File

@ -0,0 +1,16 @@
[package]
name = "ovlach_pdf"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde_yaml = "0.9.27"
serde = { version = "1.0", features = ["derive"] }
log = "0.4.20"
fern = "0.6.2"
rocket = { version = "0.5.0", features = ["json"] }
headless_chrome = "1.0.8"
ovlach_data = { git = "ssh://git@gitlab.nanobyte.cz/ondrej/ov-site-api-data.git", branch = "add_missing_fields"}

2
Rocket.toml Normal file
View File

@ -0,0 +1,2 @@
[debug]
port = 8003

9
src/lib.rs Normal file
View File

@ -0,0 +1,9 @@
use rocket::{Rocket, Build, routes};
pub mod routes;
pub fn rocket_builder() -> Rocket<Build> {
rocket::build().mount("/", routes![
routes::pdf::render_pdf_cv,
])
}

8
src/main.rs Normal file
View File

@ -0,0 +1,8 @@
use ovlach_pdf::rocket_builder;
use rocket::launch;
#[launch]
fn rocket() -> _ {
rocket_builder()
}

1
src/routes/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod pdf;

41
src/routes/pdf.rs Normal file
View File

@ -0,0 +1,41 @@
use std::{fs, thread};
use std::{fs::File, time::Duration};
use std::io::prelude::*;
use headless_chrome::Browser;
use headless_chrome::{types::PrintToPdfOptions, LaunchOptions};
use log::error;
use rocket::{get, Response, futures::Stream, tokio::net::UnixStream, fs::NamedFile};
fn generate_pdf() {
let browser = Browser::new(LaunchOptions::default()).unwrap();
let tab = browser.new_tab().unwrap();
let tab = tab.navigate_to("file:///home/6a6996c0-1609-48b6-8ca6-affbef1b4d1d/Devel/Nanobyte/ovlach/ovlach_pdf/template.html").unwrap().wait_until_navigated().unwrap();
let options = PrintToPdfOptions{
margin_bottom: Some(0.0),
margin_left: Some(0.0),
margin_right: Some(0.0),
margin_top: Some(0.0),
print_background: Some(true),
//paper_width: Some(29.7),
//paper_height: Some(21.0),
..PrintToPdfOptions::default()
};
//thread::sleep(Duration::from_secs(10));
let bytes = tab.print_to_pdf(Some(options)).unwrap();
let mut file = fs::OpenOptions::new()
// .create(true) // To create a new file
.write(true)
// either use the ? operator or unwrap since it returns a Result
.open("/tmp/foo.pdf").unwrap();
file.write_all(&bytes).unwrap();
}
#[get("/cv/<username>/pdf")]
pub async fn render_pdf_cv(username: &str) -> NamedFile {
generate_pdf();
"foo!".to_string();
NamedFile::open("/tmp/foo.pdf").await.expect("failed to open foo.pdf")
}

199
template.html Normal file
View File

@ -0,0 +1,199 @@
<html>
<head>
<meta charset="UTF-8">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;800&family=Roboto&display=swap" rel="stylesheet">
<style>
h1 {
/*font-weight: 800;*/
font-size: 3em;
padding: 0;
margin: 0;
/* text upper */
text-transform: uppercase;
}
h2 {
font-size: 1.1em;
padding: 0;
margin: 0;
}
body { min-height: 100vh; }
body {
padding: 0;
margin: 0;
font-family: 'Roboto' ;
min-height: 100%;
}
.about-me-small, .company {
color: #39c0ed;
}
.part-content > * {
padding-bottom: 0.2em;
}
.part {
padding-top: 1em;
font-size: 10pt;
}
.flex-container {
min-height: 100vh;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-items: normal;
align-content: normal;
width: 100%;
}
.flex-items:nth-child(1) {
display: block;
flex-grow: 1;
flex-shrink: 1;
flex-basis: auto;
align-self: auto;
order: 0;
}
.flex-items:nth-child(2) {
display: block;
flex-grow: 0;
flex-shrink: 1;
flex-basis: auto;
align-self: auto;
order: 0;
width: 30%;
background-color: gray;
}
.section-header {
border-bottom: 1px solid gray;
width: 99%;
margin-bottom: 1em;
}
.flex-container-experience {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: normal;
align-items: normal;
align-content: normal;
}
.flex-items-experience:nth-child(1) {
display: block;
flex-grow: 0;
flex-shrink: 1;
flex-basis: auto;
align-self: auto;
width: 70%;
order: 0;
}
.flex-items-experience:nth-child(2) {
display: block;
flex-grow: 0;
flex-shrink: 1;
flex-basis: auto;
text-align: right;
align-self: auto;
width: 30%;
margin-right: 1%;
order: 0;
}
</style>
</head>
<body>
<div class="flex-container">
<div class="flex-items">
<div class="header">
<h1>Ondřej Vlach</h1>
<div class="about-me-small">Software engineer</div>
</div>
<div class="part">
<div class="section-header">
<h2>Experience</h2>
</div>
<div class="job part-content">
<div class="flex-container-experience">
<div class="flex-items-experience">
<div class="title">Title</div>
<div class="company">Company</div>
<div class="languages">PHP HTML Aholamora Snake</div>
<p>
baklklbkalkblaklkb lakbl aklkbl akblka lkblakbla
</p>
</div>
<div class="flex-items-experience">
<div class="location">Location</div>
<div class="dates">Dates</div>
</div>
</div>
</div>
</div>
<div class="part">
<div class="section-header">
<h2>Experience</h2>
</div>
<div class="job part-content">
<div class="flex-container-experience">
<div class="flex-items-experience">
<div class="title">Title</div>
<div class="company">Company</div>
<div class="languages">PHP HTML Aholamora Snake</div>
<p>
baklklbkalkblaklkb lakbl aklkbl akblka lkblakbla
</p>
</div>
<div class="flex-items-experience">
<div class="location">Location</div>
<div class="dates">Dates</div>
</div>
</div>
</div>
</div>
<div class="part">
<div class="section-header">
<h2>Experience</h2>
</div>
<div class="job part-content">
<div class="flex-container-experience">
<div class="flex-items-experience">
<div class="title">Title</div>
<div class="company">Company</div>
<div class="languages">PHP HTML Aholamora Snake</div>
<p>
baklklbkalkblaklkb lakbl aklkbl akblka lkblakbla
</p>
</div>
<div class="flex-items-experience">
<div class="location">Location</div>
<div class="dates">Dates</div>
</div>
</div>
</div>
</div>
</div>
<div class="flex-items">
Photo2342342314213 423142342314213423
<div class="contact-bar">
<span class="phone">L</span>
<span class="email">L</span>
</div>
</div>
</div>
</body>
</html>