tonhowtf/omniget · error

ghostscript falhou

Error message

ghostscript falhou: {}

What it means

In compression mode "gs", the tool shells out to the ghostscript binary; if the command ran but exited with failure, it throws "ghostscript falhou: {stderr}" including ghostscript's own error output. This indicates ghostscript rejected the arguments or the input PDF.

Solutions

  1. Read the stderr fragment in the error — it names the actual gs problem.
  2. Run `gs ... input.pdf` manually with the same args to reproduce and debug.
  3. Remove the password (qpdf --decrypt) if the PDF is encrypted.
  4. Update/reinstall ghostscript if the device (pdfwrite) is missing.
  5. Fall back to another compression mode instead of "gs".

Example fix

// before
compress(&CompressOptions { mode: "gs".into(), input: encrypted_pdf, .. })

// after
// decrypt first
std::process::Command::new("qpdf").args(["--decrypt", "in.pdf", "dec.pdf"]).status()?;
compress(&CompressOptions { mode: "gs".into(), input: "dec.pdf".into(), .. })
Defensive patterns

Strategy: try-catch

Validate before calling

let gs = which::which("gs").is_ok();
let encrypted = std::fs::read(&opts.input)
    .map(|d| String::from_utf8_lossy(&d).contains("/Encrypt"))
    .unwrap_or(false);
if !gs { return Err("ghostscript not installed"); }
if encrypted { return Err("decrypt the PDF first (qpdf --decrypt)"); }

Try / catch

match compress(&opts, &progress).await {
    Ok(out) => use(out),
    Err(e) if e.to_string().contains("ghostscript falhou") => {
        eprintln!("gs stderr: {} — run gs manually to debug", e);
    }
    Err(e) => eprintln!("compress failed: {e}"),
}

Prevention

When it happens

Trigger: opts.mode == "gs" and the ghostscript process returned a non-zero exit: bad/unsupported gs options, encrypted or corrupt input PDF, unreadable output path, or a ghostscript version lacking the requested device (e.g. pdfwrite).

Common situations: Password-protected PDFs; ghostscript installed via minimal package missing pdfwrite; output directory not writable; extremely large PDFs hitting resource limits.

Related errors


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

Appendix: source

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

                move || {
                    info(&out.to_string_lossy(), None)
                        .map(|i| i.pages)
                        .unwrap_or(0)
                }
            })
            .await
            .unwrap_or(0);
            report(&progress, "done", 1, Some(1), None);
            return Ok(CompressResult {
                output: output.to_string_lossy().to_string(),
                before,
                after,
                method: "ghostscript".into(),
                pages,
            });
        }
        if opts.mode == "gs" {
            return Err(anyhow!(
                "ghostscript falhou: {}",
                String::from_utf8_lossy(&o.stderr).trim()
            ));
        }
        let _ = std::fs::remove_file(&output);
    } else if opts.mode == "gs" {
        return Err(anyhow!("Ghostscript nao encontrado"));
    }
    let dpi = if opts.dpi == 0 { 110 } else { opts.dpi };
    let quality = if opts.quality == 0 { 60 } else { opts.quality };
    let out =
        tokio::task::spawn_blocking(move || rasterize(&input, &output, dpi, quality, &progress))
            .await??;
    Ok(CompressResult {
        output: out.output,
        before,
        after: out.bytes,
        method: "raster".into(),

View on GitHub (pinned to 8600b91f42)