tonhowtf/omniget · error

nao carregou o PDFium em

Error message

nao carregou o PDFium em {}: {}

What it means

api() wraps libloading::Library::new failure with this message after a path was resolved. The library file was found but could not be loaded as a dynamic library — wrong architecture, missing transitive dependencies, corrupted file, or insufficient permissions. The message includes the path and the OS loader error, which is the key diagnostic.

Solutions

  1. Read the inner libloading/OS error in the message to identify the load failure cause
  2. Install the PDFium build matching the app's architecture and platform
  3. On Linux install missing shared-library dependencies (ldd the pdfium file); on macOS clear the quarantine attribute (xattr -d com.apple.quarantine)
  4. Re-download/reinstall PDFium — the file may be truncated or corrupted

Example fix

// before
let pages = pdf::render(path, opts)?; // 'nao carregou o PDFium em /opt/.../libpdfium.so: ...'
// after
match pdf::render(path, opts) {
    Err(e) if e.to_string().contains("nao carregou o PDFium") => {
        repair_pdfium_install()?; // reinstall correct arch + deps
        let pages = pdf::render(path, opts)?;
    }
    r => r?,
}
Defensive patterns

Strategy: try-catch

Validate before calling

fn pdfium_loadable(p: &std::path::Path) -> Result<(), String> {
    // loader-level probe
    match unsafe { libloading::Library::new(p) } {
        Ok(_) => Ok(()),
        Err(e) => Err(format!("falha ao carregar {}: {e}\nVerifique arquitetura e dependências do sistema.", p.display())),
    }
}

Try / catch

match pdf::split(&path, &out_dir) {
    Err(e) if e.to_string().contains("nao carregou o PDFium") => {
        eprintln!("{e}\nReinstale o PDFium da arquitetura correta via Ajustes → Dependências.");
    }
    other => other?,
}

Prevention

When it happens

Trigger: Calling any PDF operation when the resolved PDFium file cannot be dlopen'd/LoadLibrary'd: 32/64-bit mismatch, missing libstdc++/libc++ deps of pdfium, quarantine/provisioning blocking load on macOS, truncated download.

Common situations: Downloading the wrong-architecture pdfium binary; on Linux missing system libs pdfium links against; macOS Gatekeeper quarantine bit; partially downloaded library file.

Related errors


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

Appendix: source

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

    Ok(*lib
        .get::<T>(name)
        .map_err(|e| anyhow!("PDFium sem {}: {}", String::from_utf8_lossy(name), e))?)
}

/// Igual ao `sym`, mas o símbolo pode faltar: devolve `None` em vez de erro.
unsafe fn opt_sym<T: Copy>(lib: &libloading::Library, name: &[u8]) -> Option<T> {
    lib.get::<T>(name).ok().map(|s| *s)
}

fn api() -> anyhow::Result<&'static Api> {
    let mut guard = API.lock().unwrap_or_else(|p| p.into_inner());
    if let Some(a) = *guard {
        return Ok(a);
    }
    let path = crate::core::pdfium::resolve_path()
        .ok_or_else(|| anyhow!("PDFium nao esta instalado (Ajustes → Dependencias → PDFium)"))?;
    let lib = unsafe { libloading::Library::new(&path) }
        .map_err(|e| anyhow!("nao carregou o PDFium em {}: {}", path.display(), e))?;
    let api = unsafe {
        let init: unsafe extern "C" fn() = sym(&lib, b"FPDF_InitLibrary\0")?;
        init();
        Api {
            load_mem: sym(&lib, b"FPDF_LoadMemDocument64\0")?,
            last_error: sym(&lib, b"FPDF_GetLastError\0")?,
            page_count: sym(&lib, b"FPDF_GetPageCount\0")?,
            load_page: sym(&lib, b"FPDF_LoadPage\0")?,
            page_w: sym(&lib, b"FPDF_GetPageWidthF\0")?,
            page_h: sym(&lib, b"FPDF_GetPageHeightF\0")?,
            close_page: sym(&lib, b"FPDF_ClosePage\0")?,
            close_doc: sym(&lib, b"FPDF_CloseDocument\0")?,
            bmp_create: sym(&lib, b"FPDFBitmap_Create\0")?,
            bmp_fill: sym(&lib, b"FPDFBitmap_FillRect\0")?,
            render: sym(&lib, b"FPDF_RenderPageBitmap\0")?,
            bmp_buffer: sym(&lib, b"FPDFBitmap_GetBuffer\0")?,
            bmp_stride: sym(&lib, b"FPDFBitmap_GetStride\0")?,
            bmp_destroy: sym(&lib, b"FPDFBitmap_Destroy\0")?,

View on GitHub (pinned to 8600b91f42)