diff options
Diffstat (limited to 'crates/typst-cli')
| -rw-r--r-- | crates/typst-cli/src/args.rs | 17 | ||||
| -rw-r--r-- | crates/typst-cli/src/compile.rs | 17 |
2 files changed, 33 insertions, 1 deletions
diff --git a/crates/typst-cli/src/args.rs b/crates/typst-cli/src/args.rs index d1cbefae..6505994b 100644 --- a/crates/typst-cli/src/args.rs +++ b/crates/typst-cli/src/args.rs @@ -122,6 +122,23 @@ pub struct CompileCommand { /// apart from file names and line numbers. #[arg(long = "timings", value_name = "OUTPUT_JSON")] pub timings: Option<Option<PathBuf>>, + + /// One (or multiple comma-separated) PDF standards that Typst will enforce + /// conformance with. + #[arg(long = "pdf-standard", value_delimiter = ',')] + pub pdf_standard: Vec<PdfStandard>, +} + +/// A PDF standard. +#[derive(Debug, Copy, Clone, Eq, PartialEq, ValueEnum)] +#[allow(non_camel_case_types)] +pub enum PdfStandard { + /// PDF 1.7. + #[value(name = "1.7")] + V_1_7, + /// PDF/A-2b. + #[value(name = "a-2b")] + A_2b, } /// Initializes a new project from a template diff --git a/crates/typst-cli/src/compile.rs b/crates/typst-cli/src/compile.rs index 58745c80..b1786941 100644 --- a/crates/typst-cli/src/compile.rs +++ b/crates/typst-cli/src/compile.rs @@ -16,10 +16,11 @@ use typst::layout::{Frame, Page, PageRanges}; use typst::model::Document; use typst::syntax::{FileId, Source, Span}; use typst::WorldExt; -use typst_pdf::PdfOptions; +use typst_pdf::{PdfOptions, PdfStandards}; use crate::args::{ CompileCommand, DiagnosticFormat, Input, Output, OutputFormat, PageRangeArgument, + PdfStandard, }; use crate::timings::Timer; use crate::watch::Status; @@ -78,6 +79,19 @@ impl CompileCommand { ) }) } + + /// The PDF standards to try to conform with. + pub fn pdf_standards(&self) -> StrResult<PdfStandards> { + let list = self + .pdf_standard + .iter() + .map(|standard| match standard { + PdfStandard::V_1_7 => typst_pdf::PdfStandard::V_1_7, + PdfStandard::A_2b => typst_pdf::PdfStandard::A_2b, + }) + .collect::<Vec<_>>(); + PdfStandards::new(&list) + } } /// Execute a compilation command. @@ -179,6 +193,7 @@ fn export_pdf(document: &Document, command: &CompileCommand) -> SourceResult<()> command.common.creation_timestamp.unwrap_or_else(chrono::Utc::now), ), page_ranges: command.exported_page_ranges(), + standards: command.pdf_standards().at(Span::detached())?, }; let buffer = typst_pdf::pdf(document, &options)?; command |
