緣起:當GMT助教時,想很快的把所有同學的作業(PostScript檔, PS檔)很快的合成一個 PDF 檔,可以快速的看過所有同學的作業再評分,因此就稍微找了一下相關的指令,發現挺簡單的:D
環境:
作業系統:Mac OSX 10.12
- Ghostscript 9.21 (build from source with –with-x11 by homebrew )
- GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
主要指令:先用 find 指令找出所有 *.ps 檔案,再用 Ghostscript 批次處理。
fl=`find . -type f -name *.ps` gs -sDEVICE=pdfwrite \ -dNOPAUSE \ -dBATCH \ -dSAFER \ -sOutputFile=ex01_combined.pdf \ ${fl}
簡單說明:
- 設定變數:fl=` command ` 將 command 輸出的內容設定為 fl 的變數,這邊用 find 將所有 .ps 結尾的檔案列出。
- 使用 gs 將檔案批次處理,合併成單一 PDF 檔案。設定輸出檔名:-sOutputFile=輸出檔名。gs 其實可以處理不止 PS 檔案,PDF、EPS等等都可以混和幫你合併起來,有人甚至還有教學如何用 ghostscript 設定印表機。
參考資料:
- http://www.linuxjournal.com/content/tech-tip-using-ghostscript-convert-and-combine-files
- http://www.binarytides.com/linux-find-command-examples/