tonhowtf/omniget · error
conteúdo
Error message
conteúdo: {} What it means
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: {}'.
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
Example fix
// before
let content = Content { operations: stamp_ops(&text, tm, size, gray) };
// after
assert!(size.is_finite() && tm.iter().all(|v| v.is_finite()));
let text: String = text.chars().map(|c| if c.is_ascii() { c } else { '?' }).collect();
let content = Content { operations: stamp_ops(&text, tm, size, gray) }; Defensive patterns
Strategy: validation
Validate before calling
assert!(size.is_finite()); assert!(text.is_char_boundary(text.len())); let ascii_safe: String = text.chars().filter(|c| c.is_ascii()).collect(); assert!(!ascii_safe.is_empty());
Try / catch
let encoded = content.encode()
.map_err(|e| anyhow!("operações de carimbo inválidas: {}", e))?; Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/4941b1c079da6d0d.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/omniget-core/src/core/tools/pdf_write.rs:387
for (index, (_, page_id)) in ids.iter().enumerate() {
let (w, h) = page_size(&doc, *page_id);
let text = if opts.mode == "bates" {
format!("{}{:06}", opts.prefix, opts.start_number as usize + index)
} else {
opts.text.clone()
};
let size = if opts.mode == "bates" {
opts.font_size.min(14.0)
} else {
opts.font_size
};
let tm = placement(&opts.mode, w, h, text_width(&text, size), size);
let content = Content {
operations: stamp_ops(&text, tm, size, gray),
};
let stream_id = doc.add_object(Stream::new(
dictionary! {},
content.encode().map_err(|e| anyhow!("conteúdo: {}", e))?,
));
if let Some(res_id) = resource_dict_id(&mut doc, *page_id) {
if let Ok(res) = doc.get_dictionary_mut(res_id) {
let mut fonts = res
.get(b"Font")
.and_then(Object::as_dict)
.cloned()
.unwrap_or_default();
fonts.set("OGWMfont", Object::Reference(font_id));
res.set("Font", Object::Dictionary(fonts));
let mut gss = res
.get(b"ExtGState")
.and_then(Object::as_dict)
.cloned()
.unwrap_or_default();
gss.set("OGWMgs", Object::Reference(gs_id));
res.set("ExtGState", Object::Dictionary(gss));View on GitHub (pinned to 8600b91f42)