Skip to content

Instantly share code, notes, and snippets.

@su8
Created November 12, 2025 18:04
Show Gist options
  • Select an option

  • Save su8/1bebd9cd1170bbf550b793a395fcaeae to your computer and use it in GitHub Desktop.

Select an option

Save su8/1bebd9cd1170bbf550b793a395fcaeae to your computer and use it in GitHub Desktop.
main16.rs
use std::process::Command;
use std::path::Path;
use std::fs::read_dir;
use std::thread;
use std::sync::Arc;
use crossbeam::scope;
fn optimize_pdf(pdf_path: &Path) {
let output_path = pdf_path.with_name(format!("optimized_{}", pdf_path.file_name().unwrap().to_str().unwrap()));
let mut cmd = Command::new("gs");
cmd.arg("-sDEVICE=pdfwrite");
cmd.arg("-dNOPAUSE");
cmd.arg("-dBATCH");
cmd.arg("-dQUIET");
cmd.arg(format!("-sOutputFile={}", output_path.display()));
cmd.arg(pdf_path.display());
cmd.spawn().unwrap().wait().unwrap();
}
fn main() {
let mut pdf_files = Vec::new();
for entry in read_dir(".").unwrap() {
let entry = entry.unwrap();
let path = entry.path();
if path.extension().unwrap() == "pdf" {
pdf_files.push(path);
}
}
let pdf_files = Arc::new(pdf_files);
scope::spawn(move || {
for pdf_file in pdf_files.iter() {
optimize_pdf(pdf_file);
}
}).unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment