-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_pdf_to_pdf-a.php
103 lines (91 loc) · 3.77 KB
/
process_pdf_to_pdf-a.php
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
<?php
$start_time = explode(' ', microtime()); $start_time = $start_time[1] + $start_time[0];
$count=0;
error_reporting(-1);
print $spacer="##############################################################################\n";
echo date('M d, Y H:i:s');
print "\n".$spacer;
include_once "settings.php";
/** If you do not have your own settings files, you can set them here. **/
if (!isset($rootPath))
echo $rootPath = "/directory/";
if (!isset($processedFolder))
$processedFolder = "Orders\ Processed/";
/** Ghost Script installed through MacPorts **/
$command = "/opt/local/bin/gs -dPDFA -sDEVICE=pdfwrite -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -sOutputFile=";
checkVolume($rootPath, $smbLogin, $smbPassword, $smbServer, $smbShare);
$rootDirectory = dirToArray($rootPath);
if (isset($argv['1']) == TRUE)
$rootDirectory = array("ORDERS_".$argv['1']);
if ($rootDirectory != NULL)
{
foreach ($rootDirectory as $key => $dirOrders)
{
$folder = folderToArray($rootPath.$dirOrders);
foreach ($folder as $num => $fileName)
{
if (substr($fileName, 0, 7) != "(PDF-A)")
{
$runExec = $command.$rootPath.$dirOrders."/\"(PDF-A) ".$fileName."\" ".$rootPath.$dirOrders."/\"".$fileName."\" \n";
$runMove = "mv ".$rootPath.$dirOrders."/\"".$fileName."\" ".$rootPath.$processedFolder."PDF-A\ Processed/".$dirOrders."/\"".$fileName."\"\n";
/** I'm not actively running this, but if I wanted to, I just uncomment the following lines. **/
// $outputConvert = shell_exec($runExec);
// $outputMove = shell_exec($runMove);
$count++;
}
}
}
} else { echo "\n\tDirectory not found\n"; }
$end_time = explode(' ', microtime()); $total_time = $end_time[0] + $end_time[1] - $start_time;
print "\n".$spacer;
printf('Runtime: %.3f seconds. %d files processed', $total_time, $count);
print "\n".$spacer;
shell_exec("umount ".$rootPath." > /dev/null");
/******************************************************************************************************/
function checkVolume($vol, $smbLogin, $smbPassword, $smbServer, $smbShare)
{
if(!is_dir($vol))
{
echo "Mounting Orders Drive\n\n";
$outputMount = shell_exec("osascript -e 'mount volume \"smb://".$smbLogin.":".$smbPassword."@".$smbServer."/".$smbShare."\"' > /dev/null");
}
}
/******************************************************************************************************/
function dirToArray($dir, $orderDIR="") {
if(is_dir($dir))
{
$result = array();
$cdir = scandir($dir);
foreach ($cdir as $key => $value)
{
if (preg_match("/^ORDERS/", $value)) {
if (is_dir($dir . DIRECTORY_SEPARATOR . $value))
$orderDIR[] = $value;
}
}
sort($orderDIR);
return $orderDIR;
} else {return NULL;}
}
/******************************************************************************************************/
/******************************************************************************************************/
function folderToArray($dir) {
$result = array();
$cdir = scandir($dir);
foreach ($cdir as $key => $file)
{
$ext = strtolower(strrchr( $file, '.' ));
if (strcasecmp($ext,'.pdf')== 0)
if (!in_array($file,array(".","..",".DS_Store","UdBinInfo.dat")))
{
if (is_dir($dir . DIRECTORY_SEPARATOR . $file))
{ $result[$file] = dirToArray($dir . DIRECTORY_SEPARATOR . $file); }
else
{ $result[] = $file; }
}
}
sort($result);
return $result;
}
/******************************************************************************************************/
?>