tonhowtf/omniget · error
não abri o PDF
Error message
não abri o PDF: {} What it means
In pdf_redact's load(), opening the input PDF failed. The lopdf error from Document::load / Document::load_mem_with_options is wrapped with 'não abri o PDF: {}'. For password-protected files it reads bytes and loads with LoadOptions::with_password.
Solutions
- Verify the path exists and is a valid PDF before calling run
- Supply the correct user/owner password in opts.password for encrypted PDFs
- Open the file outside the closure to distinguish not-found from parse errors
- Check the wrapped lopdf error detail for the exact cause
Example fix
// before
let pw = if opts.password.is_empty() { None } else { Some(opts.password.as_str()) };
let doc = load(&opts.input, pw)?;
// after
if !std::path::Path::new(&opts.input).exists() { bail!("file not found: {}", opts.input); }
let doc = load(&opts.input, pw).map_err(|e| e.context("wrong password or corrupt PDF"))?; Defensive patterns
Strategy: validation
Validate before calling
let p = std::path::Path::new(input);
if !p.exists() { bail!("file not found: {}", input); }
let head = std::fs::read(p)?.get(..5).map(|b| b == b"%PDF-").unwrap_or(false);
if !head { bail!("not a PDF"); } Type guard
fn is_loadable(path: &str, pw: &str) -> bool {
match if pw.is_empty() { lopdf::Document::load(path) } else {
lopdf::Document::load_mem_with_options(&std::fs::read(path).unwrap_or_default(), lopdf::LoadOptions::with_password(pw))
} { Ok(_) => true, Err(_) => false }
} Try / catch
match load(input, pw) {
Err(e) if e.to_string().contains("não abri o PDF") => Err(anyhow!("wrong password or corrupt PDF: {}", e)),
r => r,
} Prevention
- Prompt for a password when the PDF reports encryption
- Validate the %PDF- header before processing
- Check the file still exists after UI selection
When it happens
Trigger: Input path does not exist or is unreadable; the file is not a valid PDF (corrupt/truncated); an encrypted PDF was loaded with a missing or wrong password.
Common situations: User picked a locked PDF without entering the password; wrong password supplied; file moved/deleted between selection and processing; .docx or other non-PDF passed in.
Understand the failure class
Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.
Related errors
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/726c60d68e860b62.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/omniget-core/src/core/tools/pdf_redact.rs:520
.file_stem()
.map(|s| s.to_string_lossy().to_string())
.unwrap_or_else(|| "documento".into());
let suffix = if opts.suffix.trim().is_empty() {
"-tarjado"
} else {
opts.suffix.trim()
};
Ok(dir.join(format!("{}{}.pdf", stem, suffix)))
}
fn load(input: &str, password: &str) -> anyhow::Result<Document> {
let doc = if password.is_empty() {
Document::load(input)
} else {
let bytes = std::fs::read(input)?;
Document::load_mem_with_options(&bytes, lopdf::LoadOptions::with_password(password))
};
doc.map_err(|e| anyhow!("não abri o PDF: {}", e))
}
/// Fontes da página que usam código de 2 bytes (Type0/Identity).
fn two_byte_fonts(doc: &Document, page_id: lopdf::ObjectId) -> Vec<String> {
let mut out = Vec::new();
let Ok((_, res_ids)) = doc.get_page_resources(page_id) else {
return out;
};
let mut dicts: Vec<lopdf::Dictionary> = Vec::new();
if let Ok(page) = doc.get_dictionary(page_id) {
if let Ok(r) = page.get(b"Resources") {
if let Ok(d) = r.as_dict() {
dicts.push(d.clone());
}
}
}
for id in res_ids {
if let Ok(d) = doc.get_dictionary(id) {View on GitHub (pinned to 8600b91f42)