tinymist_task/compute/
pdf.rs1use tinymist_std::time::ToUtcDateTime;
4pub use typst_pdf::PdfStandard as TypstPdfStandard;
5pub use typst_pdf::pdf;
6
7use typst_pdf::{PdfOptions, PdfStandards, Timestamp};
8
9use super::*;
10use crate::model::ExportPdfTask;
11
12pub struct PdfExport;
14
15impl<F: CompilerFeat> ExportComputation<F, TypstPagedDocument> for PdfExport {
16 type Output = Bytes;
17 type Config = ExportPdfTask;
18
19 fn run(
20 _graph: &Arc<WorldComputeGraph<F>>,
21 doc: &Arc<TypstPagedDocument>,
22 config: &ExportPdfTask,
23 ) -> Result<Bytes> {
24 let creation_timestamp = config
25 .creation_timestamp
26 .map(|ts| ts.to_utc_datetime().context("timestamp is out of range"))
27 .transpose()?
28 .unwrap_or_else(tinymist_std::time::utc_now);
29 let timestamp = Timestamp::new_utc(tinymist_std::time::to_typst_time(creation_timestamp));
32
33 let standards = PdfStandards::new(
34 &config
35 .pdf_standards
36 .iter()
37 .map(|standard| match standard {
38 tinymist_world::args::PdfStandard::V_1_7 => typst_pdf::PdfStandard::V_1_7,
39 tinymist_world::args::PdfStandard::A_2b => typst_pdf::PdfStandard::A_2b,
40 tinymist_world::args::PdfStandard::A_3b => typst_pdf::PdfStandard::A_3b,
41 })
42 .collect::<Vec<_>>(),
43 )
44 .context_ut("prepare pdf standards")?;
45
46 Ok(Bytes::new(typst_pdf::pdf(
49 doc,
50 &PdfOptions {
51 timestamp: Some(timestamp),
52 standards,
53 ..Default::default()
54 },
55 )?))
56 }
57}