tonhowtf/omniget · error
o PDF nao tem paginas
Error message
o PDF nao tem paginas
What it means
During split preparation, the source document's page count (src.pages()) is checked; if it is 0 the tool throws "o PDF nao tem paginas" ("the PDF has no pages"). Splitting an empty PDF is impossible, so the operation aborts before computing groups.
Solutions
- Verify the input file opens in a viewer and has pages before splitting.
- Re-generate or re-download the source PDF.
- Repair the PDF with a tool like qpdf/ghostscript (qpdf --check input.pdf).
- Check src.pages() upstream and surface a clearer user-facing error.
Example fix
// before
split(&SplitOptions { input: path, .. }, progress)
// after
if src_pages(path) > 0 { split(&SplitOptions { input: path, .. }, progress) } else { eprintln!("corrupt or empty PDF: {}", path) } Defensive patterns
Strategy: validation
Validate before calling
let meta = std::fs::metadata(&opts.input)?;
if meta.len() == 0 {
return Err(format!("{} is empty/corrupt", opts.input));
}
// optional: open with lopdf and count pages before split Type guard
fn looks_like_pdf(bytes: &[u8]) -> bool {
bytes.starts_with(b"%PDF-") && bytes.windows(5).rev().any(|w| w == b"%%EOF")
} Try / catch
match split(&opts, &progress) {
Ok(out) => use(out),
Err(e) if e.to_string().contains("nao tem paginas") => {
eprintln!("{} is corrupt or has zero pages; re-obtain the file", opts.input);
}
Err(e) => return Err(e),
} Prevention
- Check file size > 0 and a %PDF- header before processing.
- Run qpdf --check on suspicious files.
- Avoid ingesting truncated downloads; verify checksums where available.
When it happens
Trigger: Calling split with opts.input pointing to a PDF that reports 0 pages — typically a corrupt, truncated, or zero-byte file that lopdf still manages to open, or an empty PDF generated by another tool.
Common situations: Downloaded/interrupted PDFs with a valid header but no page tree; PDF writers producing empty documents on failure; files renamed to .pdf without conversion.
Understand the failure class
Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.
Related errors
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/8b883f98ac881bea.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/omniget-core/src/core/tools/pdf.rs:873
pub ranges: String,
#[serde(default)]
pub output_dir: String,
}
#[derive(Debug, Clone, Serialize)]
pub struct PdfOuts {
pub outputs: Vec<String>,
pub pages: usize,
}
pub fn split(opts: &SplitOptions, progress: &super::ProgressFn) -> anyhow::Result<PdfOuts> {
let api = api()?;
let _g = OPS.lock().unwrap_or_else(|p| p.into_inner());
let input = Path::new(opts.input.trim());
let src = Document::open(api, input, None)?;
let total = src.pages();
if total == 0 {
return Err(anyhow!("o PDF nao tem paginas"));
}
let groups: Vec<(String, Vec<usize>)> = match opts.mode.as_str() {
"each" => (1..=total)
.map(|p| (format!("p{:03}", p), vec![p]))
.collect(),
"every" => {
let n = opts.every.max(1);
(1..=total)
.collect::<Vec<_>>()
.chunks(n)
.map(|c| (format!("p{:03}-{:03}", c[0], c[c.len() - 1]), c.to_vec()))
.collect()
}
"ranges" => opts
.ranges
.split(';')
.map(str::trim)
.filter(|s| !s.is_empty())View on GitHub (pinned to 8600b91f42)