Skip to main content

build_debug_pdf

Function build_debug_pdf 

Source
pub fn build_debug_pdf(
    graph: &PageGraph,
    report: &Report,
    metadata: &PdfMetadata,
) -> Result<(Vec<u8>, Vec<Diagnostic>)>
Expand description

Build a PDF with layout-debug overlays in memory, without filesystem access.

Use the graph and report from the same mos_layout::LayoutEngine::layout_with_debug result. Bytes and encoding diagnostics match emit_debug.

§Errors

Returns MOS0051 when the report is incompatible with the graph, or the same font-subsetting errors as build_pdf.

§Examples

use mos_core::Document;
use mos_layout::LayoutEngine;
use mos_pdf::{PdfMetadata, build_debug_pdf};

let layout = LayoutEngine::new().layout_with_debug(&Document::new("example.mos".into()));
if let Some(report) = &layout.debug {
    let (bytes, diagnostics) = build_debug_pdf(&layout.graph, report, &PdfMetadata::default())?;
    assert!(bytes.starts_with(b"%PDF-"));
    assert!(diagnostics.is_empty());
}