pdf_oxide_cli 0.3.19

CLI for pdf-oxide — the fastest PDF toolkit. 22 commands: text extraction, PDF to markdown, search, merge, split, images, compress, encrypt, watermark, forms, and more.
Documentation
use pdf_oxide::editor::{DocumentEditor, EditableDocument, SaveOptions};
use std::path::Path;

pub fn run(file: &Path, _password: &str, output: Option<&Path>) -> pdf_oxide::Result<()> {
    let mut editor = DocumentEditor::open(file)?;

    let out_path = output.map(|p| p.to_path_buf()).unwrap_or_else(|| {
        let stem = file
            .file_stem()
            .and_then(|s| s.to_str())
            .unwrap_or("output");
        std::path::PathBuf::from(format!("{stem}_decrypted.pdf"))
    });

    editor.save_with_options(
        &out_path,
        SaveOptions {
            compress: true,
            garbage_collect: true,
            ..Default::default()
        },
    )?;

    eprintln!("Decrypted {} -> {}", file.display(), out_path.display());

    Ok(())
}