To convert html to pdf please submit as POST request to /pdf url with data as below where mandatory parameters are one of the body or url including header ‘Authorization: Basic somebase64===’
pub struct Pdf {
pub landscape: Option<bool>,
pub display_header_footer: Option<bool>,
pub footer: Option<String>,
pub header: Option<String>,
pub body: Option<String>, //one of the following is mandatory: html, url
pub url: Option<String>, //one of the following is mandatory: html, url
pub margin_top: Option<f64>,
pub margin_left: Option<f64>,
pub margin_right: Option<f64>,
pub margin_bottom: Option<f64>,
pub print_background: Option<bool>,
pub prefer_css_page_size: Option<bool>,
}
Body sample can be written as follow:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/* PDF STYLING */
table.report-container {
page-break-after: always;
width: 100%;
}
thead.report-header {
display: table-header-group;
}
tfoot.report-footer {
display: table-footer-group;
}
.footer-space,
.footer {
height: 270px;
}
.footer {
position: fixed;
bottom: 0;
}
@page {
size: A4;
margin: 5mm 17mm 20mm 17mm;
}
/* rest of styles */
</style>
</head>
<body>
<table class="report-container">
<thead class="report-header">
<tr>
<th class="report-header-cell">
<div class="header-info">
<table style="padding-bottom: 32px; width: 100%; margin-bottom: 20px">
<tr>
<td>
<img style="display: block; height: 55px"
src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="
alt="Logo" width="auto" />
</td>
<td>
<table style="text-align: right; margin: 0 0 0 auto">
<tr>
<td style="font-size: 32px; font-weight: 600; padding-bottom: 10px">Faktura:
<span
style="color: #efa523; margin-left: 32px; display: inline-block">I230000028</span>
</td>
</tr>
<tr>
<td style="font-weight: 500;">Data wystawienia <span
style="font-weight: 400; display: inline-block; margin-left: 24px">16.11.2023</span>
</td>
</tr>
<tr>
<td style="font-weight: 500;">Data sprzedaży <span
style="font-weight: 400; margin-left: 24px">15.11.2023</span></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</th>
</tr>
</thead>
<tbody class="report-content">
<tr>
<td class="report-content-cell">
<h1>YOUR HTML CODE IN TABLES</h1>
</td>
</tr>
</tbody>
</table>
</body>
</html>
Consider to not change tags with classes included in styles sestion above.
Build program with taget for musl as it needs to run in alpine docker
in case you neto have already installed toolchain for musl you need to run…
rustup target add x86_64-unknown-linux-musl
cargo build -r --target x86_64-unknown-linux-musl
then build docker image
docker build ./ -t print-rs:latest
to start docker and have all ready to serve:
docker run -d --cpus=1 --cpus 3 -m 1024m --cap-add=SYS_ADMIN --name print-rs -p 2000:3000 print-rs start_server
To perform tests you need to first start application and then you can run:
cargo test
To insert printing service in you docker-compose:
pdf:
image: registry.ma-al.site/print-rs:latest
command: start_server
ports:
- "8000:3000"
restart: always
cap_add:
- SYS_ADMIN
environment:
- TZ=CET-1CES