Repository navigation
Expand file tree
/
Copy pathscript.text
More file actions
112 lines (76 loc) · 3.62 KB
/
Copy pathscript.text
File metadata and controls
112 lines (76 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// ****************************************************************************
// <p>Title: PDF Remove White Border</p>
// <p>Description: Destructively removes the White Border from raw borne digital PDFs with GhostScript (slowly)</p>
// <p>Author: jharris</p>
// <p>Tooltip: Since this script is executed on the local machine, Ghostscript 9.06 must be installed</p>
// <p>Download it here https://sourceforge.net/projects/ghostscript/files/GPL%20Ghostscript/9.06/</p>
//
// ****************************************************************************
// *** Problem categories ***
//var problemMap = window.getNewProblemMap();
Packages.com.iarchives.jobq.db.DBImage.flushCache();
pipeline = db.getPipeline();
stages = pipeline.getAllStages();
for (i = 0; i < containers.length; i++) {
if (containers.length > 1)
out.println("*** " + containers[i]);
cont = containers[i];
if (cont.getImages(db.getPipeline().createMask(db.getPipeline().getStatus("Trash.Split"))).length > 0)
exit(cont + " has split images");
images = cont.getImages();
java.util.Arrays.sort(images);
out.println("Ghostscript must be installed on your machine: https://sourceforge.net/projects/ghostscript/files/GPL%20Ghostscript/9.06/");
out.println("Checking XML Files");
nameMapping = new java.util.LinkedHashMap();
imagesToRename = new java.util.LinkedHashSet();
rawFiles = new java.util.HashSet();
imageMap = new java.util.HashMap();
imageState = new java.util.HashMap();
for (j = 0; j < images.length; j++) {
image = images[j];
name = image.getName();
imageMap.put(name, image);
imageState.put(name, image.getState());
destName = images[images.length - j - 1].getName();
nameMapping.put(name, destName);
}
for (j = 0; j < images.length; j++) {
image = images[j];
name = image.getName();
page = image.getPageXML();
rawFile = page.getRawFile();
if (rawFile == null)
exit(name + " does not reference a raw image");
imagesToRename.add(name);
}
out.println("Converting raw files here:");
paths = cont.getPaths();
rawDir = paths.getTypeDir("raw");
out.println(rawDir);
deleteMethod = rawDir.getClass().getMethod("delete", java.lang.reflect.Array.newInstance(rawDir.getClass().getClass(), 0));
raws = rawDir.listFiles();
java.util.Arrays.sort(raws);
failed = false;
for (j = 0; j < raws.length; j++) {
raw = raws[j];
if (raw.isFile()) {
var rawName = raw.getName();
var newName = rawName + "_tmp";
out.println("Ghostscripting " + rawName);
cmd = "\"C:\\Program Files\\gs\\gs9.06\\bin\\gswin64c.exe\" -q -dPDF -dNOPAUSE -sProcessColorModel=DeviceRGB -dUseCropBox -r300x300 -sDEVICE=pdfwrite -sPDFACompatibilityPolicy=1 -sOutputFile=" + rawDir + "\\" + newName + " " + rawDir + "\\" + rawName + " -c quit";
out.println("Running " + cmd);
p = java.lang.Runtime.getRuntime().exec(cmd);
p.waitFor();
out.println("Renaming/Moving temp file " + rawName);
newFile = new java.io.File(rawDir, newName);
out.println("About to rename new file: " + newFile.getAbsolutePath());
oldFile = new java.io.File(rawDir, rawName);
oldFile.delete();
var didRename = newFile.renameTo(oldFile);
out.println("Did it rename? " + didRename);
out.println("Renamed file: " + newFile.getName());
}
}
if (failed)
exit("Aborting prematurely due to rename failure(s)");
}