Skip to content

Commit e589489

Browse files
committed
Imrpove error logging + set A-2a as PDF standard
1 parent 23bf704 commit e589489

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
[package]
22
name = "typst-webservice"
3-
version = "0.5.3"
3+
version = "0.6.0"
44
license = "MIT"
55
edition = "2024"
66

77
[features]
88
default = []
9-
chrono = []
109

1110
[dependencies]
1211
axum = "0.8"

assets/example.typ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
)
6666
#let input = json("input.json")
6767

68-
= Hello [#input.name]
68+
= Hello #input.name
6969
#lorem(60)
7070

7171
#for item in input.list [

src/error.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,15 @@ impl IntoResponse for AppError {
7979
fn into_response(self) -> Response {
8080
let status = self.status_code();
8181
let reference = Uuid::new_v4();
82+
8283
error!(%reference, error = ?self, "Application error encountered");
84+
85+
if let AppError::PdfExport(diagnostics) | AppError::TypstCompilation(diagnostics) = &self {
86+
for diag in diagnostics {
87+
eprintln!("Typst compilation error {reference}: {}", diag.message);
88+
}
89+
}
90+
8391
let body = json!({
8492
"error": self.public_message(),
8593
"reference": reference.to_string(),

src/pdf.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use typst::{
99
text::{Font, FontBook},
1010
utils::LazyHash,
1111
};
12+
use typst_pdf::{PdfOptions, PdfStandard, PdfStandards, Timestamp};
1213

1314
use crate::{
1415
assets::collect_dir_contents,
@@ -202,8 +203,30 @@ impl PdfContext {
202203
});
203204

204205
let pdf_gen_start = Instant::now();
205-
let pdf_bytes = typst_pdf::pdf(&document, &Default::default())
206-
.map_err(|errors| AppError::PdfExport(errors.into_iter().collect()))?;
206+
let now = chrono::Utc::now();
207+
208+
let timestamp = Timestamp::new_utc(
209+
Datetime::from_ymd_hms(
210+
now.year(),
211+
now.month() as u8,
212+
now.day() as u8,
213+
now.hour() as u8,
214+
now.minute() as u8,
215+
now.second() as u8,
216+
)
217+
.expect("current UTC datetime should be valid"),
218+
);
219+
220+
let pdf_bytes = typst_pdf::pdf(
221+
&document,
222+
&PdfOptions {
223+
timestamp: Some(timestamp),
224+
standards: PdfStandards::new(&[PdfStandard::A_2a])
225+
.expect("PDF standards should be valid"),
226+
..Default::default()
227+
},
228+
)
229+
.map_err(|errors| AppError::PdfExport(errors.into_iter().collect()))?;
207230

208231
debug!(
209232
"PDF generation took {} ms",

0 commit comments

Comments
 (0)