{"record":{"id":"8b883f98ac881bea","repo":"tonhowtf/omniget","slug":"o-pdf-nao-tem-paginas","errorCode":null,"errorMessage":"o PDF nao tem paginas","messagePattern":"o PDF nao tem paginas","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/pdf.rs","lineNumber":873,"sourceCode":"    pub ranges: String,\n    #[serde(default)]\n    pub output_dir: String,\n}\n\n#[derive(Debug, Clone, Serialize)]\npub struct PdfOuts {\n    pub outputs: Vec<String>,\n    pub pages: usize,\n}\n\npub fn split(opts: &SplitOptions, progress: &super::ProgressFn) -> anyhow::Result<PdfOuts> {\n    let api = api()?;\n    let _g = OPS.lock().unwrap_or_else(|p| p.into_inner());\n    let input = Path::new(opts.input.trim());\n    let src = Document::open(api, input, None)?;\n    let total = src.pages();\n    if total == 0 {\n        return Err(anyhow!(\"o PDF nao tem paginas\"));\n    }\n    let groups: Vec<(String, Vec<usize>)> = match opts.mode.as_str() {\n        \"each\" => (1..=total)\n            .map(|p| (format!(\"p{:03}\", p), vec![p]))\n            .collect(),\n        \"every\" => {\n            let n = opts.every.max(1);\n            (1..=total)\n                .collect::<Vec<_>>()\n                .chunks(n)\n                .map(|c| (format!(\"p{:03}-{:03}\", c[0], c[c.len() - 1]), c.to_vec()))\n                .collect()\n        }\n        \"ranges\" => opts\n            .ranges\n            .split(';')\n            .map(str::trim)\n            .filter(|s| !s.is_empty())","sourceCodeStart":855,"sourceCodeEnd":891,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/pdf.rs#L855-L891","documentation":"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.","triggerScenarios":"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.","commonSituations":"Downloaded/interrupted PDFs with a valid header but no page tree; PDF writers producing empty documents on failure; files renamed to .pdf without conversion.","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."],"exampleFix":"// before\nsplit(&SplitOptions { input: path, .. }, progress)\n\n// after\nif src_pages(path) > 0 { split(&SplitOptions { input: path, .. }, progress) } else { eprintln!(\"corrupt or empty PDF: {}\", path) }","handlingStrategy":"validation","validationCode":"let meta = std::fs::metadata(&opts.input)?;\nif meta.len() == 0 {\n    return Err(format!(\"{} is empty/corrupt\", opts.input));\n}\n// optional: open with lopdf and count pages before split","typeGuard":"fn looks_like_pdf(bytes: &[u8]) -> bool {\n    bytes.starts_with(b\"%PDF-\") && bytes.windows(5).rev().any(|w| w == b\"%%EOF\")\n}","tryCatchPattern":"match split(&opts, &progress) {\n    Ok(out) => use(out),\n    Err(e) if e.to_string().contains(\"nao tem paginas\") => {\n        eprintln!(\"{} is corrupt or has zero pages; re-obtain the file\", opts.input);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Check file size > 0 and a %PDF- header before processing.","Run qpdf --check on suspicious files.","Avoid ingesting truncated downloads; verify checksums where available."],"tags":["pdf","split","empty-document","rust"],"backgroundTag":"empty-result-set","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}