{"record":{"id":"4941b1c079da6d0d","repo":"tonhowtf/omniget","slug":"conte-do-pdf-write","errorCode":null,"errorMessage":"conteúdo: {}","messagePattern":"conteúdo: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/pdf_write.rs","lineNumber":387,"sourceCode":"    for (index, (_, page_id)) in ids.iter().enumerate() {\n        let (w, h) = page_size(&doc, *page_id);\n        let text = if opts.mode == \"bates\" {\n            format!(\"{}{:06}\", opts.prefix, opts.start_number as usize + index)\n        } else {\n            opts.text.clone()\n        };\n        let size = if opts.mode == \"bates\" {\n            opts.font_size.min(14.0)\n        } else {\n            opts.font_size\n        };\n        let tm = placement(&opts.mode, w, h, text_width(&text, size), size);\n        let content = Content {\n            operations: stamp_ops(&text, tm, size, gray),\n        };\n        let stream_id = doc.add_object(Stream::new(\n            dictionary! {},\n            content.encode().map_err(|e| anyhow!(\"conteúdo: {}\", e))?,\n        ));\n\n        if let Some(res_id) = resource_dict_id(&mut doc, *page_id) {\n            if let Ok(res) = doc.get_dictionary_mut(res_id) {\n                let mut fonts = res\n                    .get(b\"Font\")\n                    .and_then(Object::as_dict)\n                    .cloned()\n                    .unwrap_or_default();\n                fonts.set(\"OGWMfont\", Object::Reference(font_id));\n                res.set(\"Font\", Object::Dictionary(fonts));\n                let mut gss = res\n                    .get(b\"ExtGState\")\n                    .and_then(Object::as_dict)\n                    .cloned()\n                    .unwrap_or_default();\n                gss.set(\"OGWMgs\", Object::Reference(gs_id));\n                res.set(\"ExtGState\", Object::Dictionary(gss));","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf_write.rs#L369-L405","documentation":"For each page, watermark_one builds a lopdf Content of stamp operations and serializes it with content.encode() to create the page's content stream. If encode() fails (invalid operations produced by stamp_ops/placement, e.g. NaN geometry), the error is wrapped as 'conteúdo: {}'.","triggerScenarios":"content.encode() returning Err — usually caused by invalid text or placement math feeding stamp_ops (NaN/inf from text_width or placement, or malformed operands for text-showing operators).","commonSituations":"Watermark text containing characters the chosen Type1 font cannot encode; font size or page dimensions producing NaN; a bug in placement() returning out-of-range matrix values.","solutions":["Inspect the wrapped inner error after 'conteúdo:' for the exact encoding failure","Sanitize the watermark text to WinAnsi/Latin-1 characters compatible with the Type1 font used","Ensure font size and placement inputs are finite (guard against NaN/inf)","Update lopdf if Content::encode rejects valid operations"],"exampleFix":"// before\nlet content = Content { operations: stamp_ops(&text, tm, size, gray) };\n// after\nassert!(size.is_finite() && tm.iter().all(|v| v.is_finite()));\nlet text: String = text.chars().map(|c| if c.is_ascii() { c } else { '?' }).collect();\nlet content = Content { operations: stamp_ops(&text, tm, size, gray) };","handlingStrategy":"validation","validationCode":"assert!(size.is_finite());\nassert!(text.is_char_boundary(text.len()));\nlet ascii_safe: String = text.chars().filter(|c| c.is_ascii()).collect();\nassert!(!ascii_safe.is_empty());","typeGuard":null,"tryCatchPattern":"let encoded = content.encode()\n    .map_err(|e| anyhow!(\"operações de carimbo inválidas: {}\", e))?;","preventionTips":["Restrict watermark text to WinAnsi/ASCII characters for Type1 fonts","Guard placement math against NaN/inf (zero-size pages, zero font size)","Unit-test stamp_ops/placement output before encoding"],"tags":["pdf","content-stream","encoding","lopdf"],"backgroundTag":"invalid-argument-value","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}