Skip to main content

DocumentSource

Trait DocumentSource 

Source
pub trait DocumentSource: Send + Sync {
    // Required methods
    fn page_count(&self) -> usize;
    fn page_dimensions(&self, page_index: usize) -> PageDimensions;
    fn render_page(
        &self,
        page_index: usize,
        target_size: RenderSize,
    ) -> Result<RenderedPage, DocumentError>;
    fn embedded_metadata(&self) -> Option<EmbeddedMetadata>;
    fn outline(&self) -> Option<Vec<OutlineEntry>>;
}
Expand description

Abstraction over document sources.

In v1, the only implementation is a PDF loader (hayro or mupdf-rs). This trait is the extension point for native Typst source support — a live-compiled Typst document becomes another DocumentSource implementation.

Required Methods§

Source

fn page_count(&self) -> usize

Total number of pages in the document.

Source

fn page_dimensions(&self, page_index: usize) -> PageDimensions

Dimensions of a specific page (in points).

Source

fn render_page( &self, page_index: usize, target_size: RenderSize, ) -> Result<RenderedPage, DocumentError>

Render a page to an RGBA bitmap at the specified target size.

Source

fn embedded_metadata(&self) -> Option<EmbeddedMetadata>

Extract embedded metadata (pdfpc-compatible), if present.

Source

fn outline(&self) -> Option<Vec<OutlineEntry>>

PDF outline/bookmark entries, if present.

Implementors§