tonhowtf/omniget · error

documento sem páginas

Error message

documento sem páginas

What it means

write_outline loads the PDF, collects its pages via doc.get_pages(), and refuses to proceed when the page map is empty ("document without pages"). A PDF with no page objects cannot have bookmarks attached, so the library aborts early rather than writing an outline into a degenerate document.

Solutions

  1. Check the input file is a valid, non-empty PDF with pages before calling write_outline.
  2. Re-export/repair the source PDF from its origin application.
  3. Verify you passed the correct path in opts.input (not a different/empty file).

Example fix

// before
write_outline(&OutlineOptions { input: path.into(), .. })?;
// after
let doc = lopdf::Document::load(path)?;
if doc.get_pages().is_empty() { bail!("input has no pages"); }
write_outline(&OutlineOptions { input: path.into(), .. })?;
Defensive patterns

Strategy: validation

Validate before calling

let doc = lopdf::Document::load(&opts.input)?;
if doc.get_pages().is_empty() {
    return Err(anyhow!("{}: input PDF has no pages", opts.input));
}

Try / catch

match write_outline(&opts) {
    Err(e) if e.to_string().contains("documento sem páginas") => {
        eprintln!("skipping: input has no pages");
        // fall back to skipping this file
    }
    other => other?,
}

Prevention

When it happens

Trigger: Calling write_outline with opts.input pointing to an empty, corrupted, or non-page-containing PDF (get_pages returns an empty BTreeMap).

Common situations: Passing a 0-byte or truncated file that lopdf still parses; a PDF whose page tree was stripped (e.g. some generated template files); accidentally passing a non-PDF file that lopdf loads as an empty document.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

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

            walk(doc, next, level, pages, out, depth + 1);
        }
    }
    // A raiz /Outlines não tem título: quem é nível 0 é o /First dela.
    if let Ok(first) = doc
        .get_dictionary(root)
        .and_then(|d| d.get(b"First"))
        .and_then(Object::as_reference)
    {
        walk(&doc, first, 0, &pages, &mut out, 0);
    }
    Ok(out)
}

pub fn write_outline(opts: &OutlineOptions) -> anyhow::Result<WriteItem> {
    let mut doc = load(&opts.input, "")?;
    let pages: BTreeMap<u32, lopdf::ObjectId> = doc.get_pages();
    if pages.is_empty() {
        return Err(anyhow!("documento sem páginas"));
    }
    doc.delete_outlines()
        .map_err(|e| anyhow!("não limpei o sumário antigo: {}", e))?;

    let entries = normalize_levels(&opts.entries);
    // Pilha com o id do último item de cada nível, para pendurar os filhos.
    let mut parents: Vec<u32> = Vec::new();
    for e in &entries {
        let page_id = *pages
            .get(&e.page)
            .or_else(|| pages.values().next())
            .ok_or_else(|| anyhow!("página {} não existe", e.page))?;
        let parent = if e.level == 0 {
            None
        } else {
            parents.get(e.level as usize - 1).copied()
        };
        let bookmark = lopdf::Bookmark::new(e.title.clone(), [0.0, 0.0, 0.0], 0, page_id);

View on GitHub (pinned to 8600b91f42)