Created
November 12, 2025 18:04
-
-
Save su8/1bebd9cd1170bbf550b793a395fcaeae to your computer and use it in GitHub Desktop.
main16.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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