Created
March 16, 2016 04:34
-
-
Save naoh16/89ed1e0bd85170b5dad7 to your computer and use it in GitHub Desktop.
特定フォルダ以下のpdfの余白を削除したpdfファイルを作るJSスクリプト。LaTeX作業のお供に。
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
/** RUN_PDFCROP.JS | |
* Find pdf files in "img" directory, and convert them into cropped pdf files. | |
* The job is skipped if the source file is old than the cropped file. | |
* | |
* Example: | |
* img/inc1.pdf -> img/inc1-crop.pdf (convert) | |
* img/inc1-crop.pdf -> img/inc1-crop.pdf (skip) | |
* | |
* Author: Sunao Hara ([email protected]) | |
* Last Modified: 2016-03-16 13:32:00. | |
*/ | |
/* | |
* Settings | |
*/ | |
var cmd_pdfcrop = "pdfcrop --gscmd gswin32c"; | |
//var cmd_pdfcrop = "pdfcrop --gscmd gswin32c --pdfversion 1.4"; | |
var target_dir = "img"; | |
/* | |
* Main routine | |
*/ | |
var objShell = new ActiveXObject("WScript.Shell") | |
var objFSO = new ActiveXObject("Scripting.FileSystemObject"); | |
var objFolder = objFSO.getFolder(target_dir); | |
//WScript.Echo(objFolder.path + ":"); | |
var fc = new Enumerator(objFolder.files); | |
for (; !fc.atEnd(); fc.moveNext()) { | |
var f = fc.item(); | |
if(objFSO.getExtensionName(f) == "pdf" && f.name.indexOf("-crop") < 0) { | |
//WScript.Echo(f.name + " : " + f.dateLastModified); | |
var crop_filename = target_dir + '\\' + objFSO.getBaseName(f) + "-crop.pdf";; | |
if(objFSO.FileExists(crop_filename)) { | |
var crop_f = objFSO.getFile(crop_filename); | |
//WScript.Echo(crop_f.name + " : " + crop_f.dateLastModified); | |
var src_date = new Date(f.dateLastModified); | |
var dst_date = new Date(crop_f.dateLastModified); | |
//WScript.Echo( src_date - dst_date ); | |
if( src_date - dst_date < 0 ) { | |
//WScript.Echo( "skip: " + f + ":" + (src_date - dst_date) ); | |
continue; | |
} | |
} | |
var cmdtext = cmd_pdfcrop + " " + target_dir + "/" + f.name + " " + crop_filename; | |
//WScript.Echo(cmdtext); | |
objShell.run(cmdtext); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment