{"record":{"id":"2dc7090e12388c7b","repo":"tonhowtf/omniget","slug":"n-o-consegui-medir-a-tinta-use-o-corte-fixo","errorCode":null,"errorMessage":"não consegui medir a tinta ({}); use o corte fixo","messagePattern":"não consegui medir a tinta \\((.+?)\\); use o corte fixo","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/pdf_write.rs","lineNumber":560,"sourceCode":"pub fn union_box(boxes: &[[f32; 4]]) -> Option<[f32; 4]> {\n    boxes.iter().copied().reduce(|a, b| {\n        [\n            a[0].min(b[0]),\n            a[1].min(b[1]),\n            a[2].max(b[2]),\n            a[3].max(b[3]),\n        ]\n    })\n}\n\nfn crop_one(opts: &CropOptions, input: &str) -> anyhow::Result<WriteItem> {\n    let mut doc = load(input, \"\")?;\n    let pages: Vec<lopdf::ObjectId> = doc.get_pages().values().copied().collect();\n    let mut boxes: Vec<[f32; 4]> = Vec::with_capacity(pages.len());\n\n    if opts.mode == \"auto\" {\n        let ink = super::pdf::ink_boxes(input, 96, 245)\n            .map_err(|e| anyhow!(\"não consegui medir a tinta ({}); use o corte fixo\", e))?;\n        for (i, page_id) in pages.iter().enumerate() {\n            let media = media_box(&doc, *page_id);\n            boxes.push(match ink.get(i).and_then(|b| *b) {\n                Some(b) => clamp_box(b, media, opts.padding),\n                None => media,\n            });\n        }\n    } else {\n        for page_id in &pages {\n            let m = media_box(&doc, *page_id);\n            boxes.push([\n                m[0] + opts.left,\n                m[1] + opts.bottom,\n                m[2] - opts.right,\n                m[3] - opts.top,\n            ]);\n        }\n    }","sourceCodeStart":542,"sourceCodeEnd":578,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf_write.rs#L542-L578","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Switch to mode=\"fixed\" and supply explicit crop boxes, as the message recommends","Inspect the wrapped inner error to see why ink_boxes/rasterization failed","Repair/re-export the PDF (qpdf --object-streams=disable) to normalize content streams","Lower DPI or adjust the ink threshold if rendering fails at the current 96/245 settings"],"exampleFix":"// before\ncrop_one(&CropOptions { mode: \"auto\".into(), ..Default::default() }, input)?;\n// after\nmatch crop_one(&CropOptions { mode: \"auto\".into(), ..Default::default() }, input) {\n    Ok(item) => item,\n    Err(_) => crop_one(&CropOptions { mode: \"fixed\".into(), padding: 12.0, ..Default::default() }, input)?,\n}","handlingStrategy":"fallback","validationCode":"if opts.mode == \"auto\" {\n    // ensure the file is a renderable PDF before paying the rasterization cost\n    if !is_loadable_pdf(input) { anyhow::bail!(\"PDF ilegível; use o corte fixo\"); }\n}","typeGuard":null,"tryCatchPattern":"let boxes = match super::pdf::ink_boxes(input, 96, 245) {\n    Ok(ink) => /* use auto boxes */,\n    Err(e) => {\n        eprintln!(\"medida de tinta falhou ({e}); caindo para corte fixo\");\n        vec![] /* fall back to fixed crop boxes */\n    }\n};","preventionTips":["Offer/choose fixed crop mode when auto measurement fails","Repair exotic PDFs with qpdf before auto-crop","Catch the ink_boxes error and warn instead of aborting the whole batch"],"tags":["pdf","crop","rasterization","fallback"],"backgroundTag":"file-read-failed","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}