mirror of
https://github.com/typst/typst
synced 2025-07-27 14:27:56 +08:00
feat: add cli args for PDF/UA-1 standard and to disable tagging
This commit is contained in:
parent
4894a227d2
commit
0d35ae28ad
@ -246,6 +246,13 @@ pub struct CompileArgs {
|
||||
#[arg(long = "pdf-standard", value_delimiter = ',')]
|
||||
pub pdf_standard: Vec<PdfStandard>,
|
||||
|
||||
/// By default, even when not producing a `PDF/UA-1` document, a tagged PDF
|
||||
/// document is written to provide a baseline of accessibility. In some
|
||||
/// circumstances (for example when trying to reduce the size of a document)
|
||||
/// it can be desirable to disable tagged PDF.
|
||||
#[arg(long = "disable-pdf-tags")]
|
||||
pub disable_pdf_tags: bool,
|
||||
|
||||
/// The PPI (pixels per inch) to use for PNG export.
|
||||
#[arg(long = "ppi", default_value_t = 144.0)]
|
||||
pub ppi: f32,
|
||||
@ -506,6 +513,9 @@ pub enum PdfStandard {
|
||||
/// PDF/A-4e.
|
||||
#[value(name = "a-4e")]
|
||||
A_4e,
|
||||
/// PDF/UA-1.
|
||||
#[value(name = "ua-1")]
|
||||
Ua_1,
|
||||
}
|
||||
|
||||
display_possible_values!(PdfStandard);
|
||||
|
@ -65,6 +65,8 @@ pub struct CompileConfig {
|
||||
pub open: Option<Option<String>>,
|
||||
/// A list of standards the PDF should conform to.
|
||||
pub pdf_standards: PdfStandards,
|
||||
/// Whether to write PDF (accessibility) tags.
|
||||
pub disable_pdf_tags: bool,
|
||||
/// A path to write a Makefile rule describing the current compilation.
|
||||
pub make_deps: Option<PathBuf>,
|
||||
/// The PPI (pixels per inch) to use for PNG export.
|
||||
@ -150,6 +152,7 @@ impl CompileConfig {
|
||||
output_format,
|
||||
pages,
|
||||
pdf_standards,
|
||||
disable_pdf_tags: args.disable_pdf_tags,
|
||||
creation_timestamp: args.world.creation_timestamp,
|
||||
make_deps: args.make_deps.clone(),
|
||||
ppi: args.ppi,
|
||||
@ -291,6 +294,7 @@ fn export_pdf(document: &PagedDocument, config: &CompileConfig) -> SourceResult<
|
||||
timestamp,
|
||||
page_ranges: config.pages.clone(),
|
||||
standards: config.pdf_standards.clone(),
|
||||
disable_tags: config.disable_pdf_tags,
|
||||
};
|
||||
let buffer = typst_pdf::pdf(document, &options)?;
|
||||
config
|
||||
@ -773,6 +777,7 @@ impl From<PdfStandard> for typst_pdf::PdfStandard {
|
||||
PdfStandard::A_4 => typst_pdf::PdfStandard::A_4,
|
||||
PdfStandard::A_4f => typst_pdf::PdfStandard::A_4f,
|
||||
PdfStandard::A_4e => typst_pdf::PdfStandard::A_4e,
|
||||
PdfStandard::Ua_1 => typst_pdf::PdfStandard::Ua_1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,17 +39,14 @@ pub fn convert(
|
||||
typst_document: &PagedDocument,
|
||||
options: &PdfOptions,
|
||||
) -> SourceResult<Vec<u8>> {
|
||||
// HACK
|
||||
let config = Configuration::new_with_validator(Validator::UA1);
|
||||
let settings = SerializeSettings {
|
||||
compress_content_streams: false, // true,
|
||||
compress_content_streams: true,
|
||||
no_device_cs: true,
|
||||
ascii_compatible: true, // false,
|
||||
ascii_compatible: false,
|
||||
xmp_metadata: true,
|
||||
cmyk_profile: None,
|
||||
configuration: config, // options.standards.config,
|
||||
// TODO: allow opting out of tagging PDFs
|
||||
enable_tagging: true,
|
||||
configuration: options.standards.config,
|
||||
enable_tagging: !options.disable_tags,
|
||||
render_svg_glyph_fn: render_svg_glyph,
|
||||
};
|
||||
|
||||
|
@ -54,6 +54,11 @@ pub struct PdfOptions<'a> {
|
||||
pub page_ranges: Option<PageRanges>,
|
||||
/// A list of PDF standards that Typst will enforce conformance with.
|
||||
pub standards: PdfStandards,
|
||||
/// By default, even when not producing a `PDF/UA-1` document, a tagged PDF
|
||||
/// document is written to provide a baseline of accessibility. In some
|
||||
/// circumstances, for example when trying to reduce the size of a document,
|
||||
/// it can be desirable to disable tagged PDF.
|
||||
pub disable_tags: bool,
|
||||
}
|
||||
|
||||
/// Encapsulates a list of compatible PDF standards.
|
||||
@ -105,6 +110,7 @@ impl PdfStandards {
|
||||
PdfStandard::A_4 => set_validator(Validator::A4)?,
|
||||
PdfStandard::A_4f => set_validator(Validator::A4F)?,
|
||||
PdfStandard::A_4e => set_validator(Validator::A4E)?,
|
||||
PdfStandard::Ua_1 => set_validator(Validator::UA1)?,
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,4 +194,7 @@ pub enum PdfStandard {
|
||||
/// PDF/A-4e.
|
||||
#[serde(rename = "a-4e")]
|
||||
A_4e,
|
||||
/// PDF/UA-1.
|
||||
#[serde(rename = "ua-1")]
|
||||
Ua_1,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user