tonhowtf/omniget · error

não consegui medir a tinta ({}); use o corte fixo

Error message

não consegui medir a tinta ({}); use o corte fixo

What it means

In crop mode "auto", crop_one delegates ink-coverage measurement to super::pdf::ink_boxes(input, 96, 245) (rasterizes pages and finds non-white bounding boxes). If that helper fails — render/decode error, rasterizer unavailable, unreadable page content — the error is wrapped as 'não consegui medir a tinta ({}); use o corte fixo', explicitly suggesting fixed crop mode as the alternative.

Solutions

  1. Switch to mode="fixed" and supply explicit crop boxes, as the message recommends
  2. Inspect the wrapped inner error to see why ink_boxes/rasterization failed
  3. Repair/re-export the PDF (qpdf --object-streams=disable) to normalize content streams
  4. Lower DPI or adjust the ink threshold if rendering fails at the current 96/245 settings

Example fix

// before
crop_one(&CropOptions { mode: "auto".into(), ..Default::default() }, input)?;
// after
match crop_one(&CropOptions { mode: "auto".into(), ..Default::default() }, input) {
    Ok(item) => item,
    Err(_) => crop_one(&CropOptions { mode: "fixed".into(), padding: 12.0, ..Default::default() }, input)?,
}
Defensive patterns

Strategy: fallback

Validate before calling

if opts.mode == "auto" {
    // ensure the file is a renderable PDF before paying the rasterization cost
    if !is_loadable_pdf(input) { anyhow::bail!("PDF ilegível; use o corte fixo"); }
}

Try / catch

let boxes = match super::pdf::ink_boxes(input, 96, 245) {
    Ok(ink) => /* use auto boxes */,
    Err(e) => {
        eprintln!("medida de tinta falhou ({e}); caindo para corte fixo");
        vec![] /* fall back to fixed crop boxes */
    }
};

Prevention

When it happens

Trigger: Calling crop with mode="auto" when ink_boxes fails: unsupported page content, rasterization failure at 96 DPI, invalid threshold 245, corrupt page streams, or resource limits during rendering.

Common situations: PDFs with exotic color spaces or broken content streams the renderer cannot rasterize; huge pages exhausting memory at 96 DPI; missing render backend in the build; scanned PDFs with unusual images.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/2dc7090e12388c7b. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/pdf_write.rs:560

pub fn union_box(boxes: &[[f32; 4]]) -> Option<[f32; 4]> {
    boxes.iter().copied().reduce(|a, b| {
        [
            a[0].min(b[0]),
            a[1].min(b[1]),
            a[2].max(b[2]),
            a[3].max(b[3]),
        ]
    })
}

fn crop_one(opts: &CropOptions, input: &str) -> anyhow::Result<WriteItem> {
    let mut doc = load(input, "")?;
    let pages: Vec<lopdf::ObjectId> = doc.get_pages().values().copied().collect();
    let mut boxes: Vec<[f32; 4]> = Vec::with_capacity(pages.len());

    if opts.mode == "auto" {
        let ink = super::pdf::ink_boxes(input, 96, 245)
            .map_err(|e| anyhow!("não consegui medir a tinta ({}); use o corte fixo", e))?;
        for (i, page_id) in pages.iter().enumerate() {
            let media = media_box(&doc, *page_id);
            boxes.push(match ink.get(i).and_then(|b| *b) {
                Some(b) => clamp_box(b, media, opts.padding),
                None => media,
            });
        }
    } else {
        for page_id in &pages {
            let m = media_box(&doc, *page_id);
            boxes.push([
                m[0] + opts.left,
                m[1] + opts.bottom,
                m[2] - opts.right,
                m[3] - opts.top,
            ]);
        }
    }

View on GitHub (pinned to 8600b91f42)