tonhowtf/omniget · error

nao importou as paginas

Error message

nao importou as paginas {:?}

What it means

import_pages invoked the native page-import function which returned 0 (failure), so pages from the source document could not be copied into this document. The requested page list is echoed in the message for debugging.

Solutions

  1. Validate the page list against the source document's page_count() before importing
  2. Verify the source document opens and its pages load (page() succeeds)
  3. Check the PDFs aren't encrypted or password-protected
  4. Split large merges into smaller batches to rule out native resource limits

Example fix

// before
doc.import(&src, vec![1, 5, 99])?;
// after
let n = src.page_count();
let pages: Vec<usize> = requested.into_iter().filter(|p| *p >= 1 && *p <= n).collect();
if pages.is_empty() { anyhow::bail!("no valid pages in selection"); }
doc.import(&src, pages)?;
Defensive patterns

Strategy: validation

Validate before calling

let n = src.page_count();
anyhow::ensure!(pages.iter().all(|p| (1..=n).contains(p)), "page selection out of source range 1..={n}");

Try / catch

if let Err(e) = doc.import(&src, &pages) {
    if e.to_string().starts_with("nao importou") {
        // retry per-page to isolate the offending source page
    }
}

Prevention

When it happens

Trigger: Calling import with a page spec whose indices don't exist in the source document, importing from a source document that failed to load properly, or a native-library failure while appending (e.g. object number overflow, unsupported page structure).

Common situations: Merging PDFs where the user-supplied page selection references pages beyond the source's count, merging encrypted/corrupted PDFs, combining documents produced by incompatible PDF versions.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/pdf.rs:250

        Ok(PageRef {
            api: self.api,
            page,
            _doc: self,
        })
    }

    /// Copia páginas de `src` (números 1-based, na ordem dada) para o fim.
    fn import(&self, src: &Document, pages: &[usize]) -> anyhow::Result<()> {
        let spec = pages
            .iter()
            .map(|p| p.to_string())
            .collect::<Vec<_>>()
            .join(",");
        let spec = CString::new(spec)?;
        let at = self.pages() as c_int;
        let ok = unsafe { (self.api.import_pages)(self.doc, src.doc, spec.as_ptr(), at) };
        if ok == 0 {
            return Err(anyhow!("nao importou as paginas {:?}", pages));
        }
        Ok(())
    }

    fn to_bytes(&self) -> anyhow::Result<Vec<u8>> {
        let mut w = Writer {
            fw: FileWrite {
                version: 1,
                write_block,
            },
            buf: Vec::new(),
        };
        let ok = unsafe { (self.api.save_copy)(self.doc, &mut w.fw as *mut FileWrite, 0) };
        if ok == 0 {
            return Err(anyhow!("nao gravou o PDF"));
        }
        Ok(w.buf)
    }

View on GitHub (pinned to 8600b91f42)